epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 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 | */ |
bsalomon@google.com | 971d0c8 | 2011-08-19 17:22:05 +0000 | [diff] [blame] | 7 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "BenchLogger.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 9 | #include "Benchmark.h" |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 10 | #include "CrashHandler.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 11 | #include "GMBench.h" |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 12 | #include "ResultsWriter.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 13 | #include "SkCanvas.h" |
mtklein@google.com | 78d0379 | 2013-09-10 19:42:07 +0000 | [diff] [blame] | 14 | #include "SkColorPriv.h" |
sglez@google.com | 586db93 | 2013-07-24 17:24:23 +0000 | [diff] [blame] | 15 | #include "SkCommandLineFlags.h" |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 16 | #include "SkData.h" |
bsalomon@google.com | 82a7bfc | 2012-04-16 19:11:17 +0000 | [diff] [blame] | 17 | #include "SkDeferredCanvas.h" |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 18 | #include "SkGraphics.h" |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 19 | #include "SkImageEncoder.h" |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 20 | #include "SkOSFile.h" |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 21 | #include "SkPicture.h" |
robertphillips@google.com | 770963f | 2014-04-18 18:04:41 +0000 | [diff] [blame] | 22 | #include "SkPictureRecorder.h" |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 23 | #include "SkString.h" |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 24 | #include "SkSurface.h" |
mtklein | 9ac68ee | 2014-06-20 11:29:20 -0700 | [diff] [blame] | 25 | #include "Timer.h" |
reed@android.com | 29348cb | 2009-08-04 18:17:15 +0000 | [diff] [blame] | 26 | |
djsollen@google.com | db490e9 | 2013-11-20 13:15:40 +0000 | [diff] [blame] | 27 | #if SK_SUPPORT_GPU |
| 28 | #include "GrContext.h" |
| 29 | #include "GrContextFactory.h" |
| 30 | #include "GrRenderTarget.h" |
djsollen@google.com | db490e9 | 2013-11-20 13:15:40 +0000 | [diff] [blame] | 31 | #include "gl/GrGLDefines.h" |
| 32 | #else |
| 33 | class GrContext; |
| 34 | #endif // SK_SUPPORT_GPU |
| 35 | |
mtklein@google.com | 9ef1d21 | 2013-09-13 20:39:50 +0000 | [diff] [blame] | 36 | #include <limits> |
| 37 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 38 | enum BenchMode { |
| 39 | kNormal_BenchMode, |
| 40 | kDeferred_BenchMode, |
| 41 | kDeferredSilent_BenchMode, |
| 42 | kRecord_BenchMode, |
| 43 | kPictureRecord_BenchMode |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 44 | }; |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 45 | const char* BenchMode_Name[] = { |
| 46 | "normal", "deferred", "deferredSilent", "record", "picturerecord" |
| 47 | }; |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 48 | |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 49 | static const char kDefaultsConfigStr[] = "defaults"; |
| 50 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 51 | #if SK_SUPPORT_GPU |
| 52 | static const char kGpuAPINameGL[] = "gl"; |
| 53 | static const char kGpuAPINameGLES[] = "gles"; |
| 54 | #endif |
| 55 | |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 56 | /////////////////////////////////////////////////////////////////////////////// |
| 57 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 58 | class Iter { |
| 59 | public: |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 60 | Iter() : fBenches(BenchRegistry::Head()), fGMs(skiagm::GMRegistry::Head()) {} |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 61 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 62 | Benchmark* next() { |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 63 | if (fBenches) { |
| 64 | BenchRegistry::Factory f = fBenches->factory(); |
| 65 | fBenches = fBenches->next(); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 66 | return (*f)(NULL); |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 67 | } |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 68 | |
| 69 | while (fGMs) { |
| 70 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
| 71 | fGMs = fGMs->next(); |
| 72 | if (gm->getFlags() & skiagm::GM::kAsBench_Flag) { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 73 | return SkNEW_ARGS(GMBench, (gm.detach())); |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 74 | } |
| 75 | } |
| 76 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 77 | return NULL; |
| 78 | } |
bungeman@google.com | d1a416a | 2011-05-18 18:37:07 +0000 | [diff] [blame] | 79 | |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 80 | private: |
commit-bot@chromium.org | 575d9cd | 2014-02-24 23:25:49 +0000 | [diff] [blame] | 81 | const BenchRegistry* fBenches; |
| 82 | const skiagm::GMRegistry* fGMs; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static void make_filename(const char name[], SkString* path) { |
| 86 | path->set(name); |
| 87 | for (int i = 0; name[i]; i++) { |
| 88 | switch (name[i]) { |
| 89 | case '/': |
| 90 | case '\\': |
| 91 | case ' ': |
| 92 | case ':': |
| 93 | path->writable_str()[i] = '-'; |
| 94 | break; |
| 95 | default: |
| 96 | break; |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 101 | static void saveFile(const char name[], const char config[], const char dir[], |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 102 | const SkImage* image) { |
| 103 | SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); |
| 104 | if (NULL == data.get()) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 105 | return; |
| 106 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 107 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 108 | SkString filename; |
| 109 | make_filename(name, &filename); |
| 110 | filename.appendf("_%s.png", config); |
| 111 | SkString path = SkOSPath::SkPathJoin(dir, filename.c_str()); |
| 112 | ::remove(path.c_str()); |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 113 | |
reed@google.com | ace1354 | 2014-02-06 22:00:58 +0000 | [diff] [blame] | 114 | SkFILEWStream stream(path.c_str()); |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 115 | stream.write(data->data(), data->size()); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 116 | } |
| 117 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 118 | static void perform_clip(SkCanvas* canvas, int w, int h) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 119 | SkRect r; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 120 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 121 | r.set(SkIntToScalar(10), SkIntToScalar(10), |
| 122 | SkIntToScalar(w*2/3), SkIntToScalar(h*2/3)); |
| 123 | canvas->clipRect(r, SkRegion::kIntersect_Op); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 124 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 125 | r.set(SkIntToScalar(w/3), SkIntToScalar(h/3), |
| 126 | SkIntToScalar(w-10), SkIntToScalar(h-10)); |
| 127 | canvas->clipRect(r, SkRegion::kXOR_Op); |
| 128 | } |
| 129 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 130 | static void perform_rotate(SkCanvas* canvas, int w, int h) { |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 131 | const SkScalar x = SkIntToScalar(w) / 2; |
| 132 | const SkScalar y = SkIntToScalar(h) / 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 133 | |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 134 | canvas->translate(x, y); |
| 135 | canvas->rotate(SkIntToScalar(35)); |
| 136 | canvas->translate(-x, -y); |
| 137 | } |
| 138 | |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 139 | static void perform_scale(SkCanvas* canvas, int w, int h) { |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 140 | const SkScalar x = SkIntToScalar(w) / 2; |
| 141 | const SkScalar y = SkIntToScalar(h) / 2; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 142 | |
reed@android.com | 387359e | 2009-08-04 01:51:09 +0000 | [diff] [blame] | 143 | canvas->translate(x, y); |
| 144 | // just enough so we can't take the sprite case |
| 145 | canvas->scale(SK_Scalar1 * 99/100, SK_Scalar1 * 99/100); |
| 146 | canvas->translate(-x, -y); |
| 147 | } |
| 148 | |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 149 | static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size, |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 150 | Benchmark::Backend backend, int sampleCount, |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 151 | GrContext* context) { |
| 152 | SkSurface* surface = NULL; |
| 153 | SkImageInfo info = SkImageInfo::Make(size.fX, size.fY, colorType, |
| 154 | kPremul_SkAlphaType); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 155 | |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 156 | switch (backend) { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 157 | case Benchmark::kRaster_Backend: |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 158 | surface = SkSurface::NewRaster(info); |
| 159 | surface->getCanvas()->clear(SK_ColorWHITE); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 160 | break; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 161 | #if SK_SUPPORT_GPU |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 162 | case Benchmark::kGPU_Backend: { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 163 | surface = SkSurface::NewRenderTarget(context, info, sampleCount); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 164 | break; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 165 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 166 | #endif |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 167 | case Benchmark::kPDF_Backend: |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 168 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 169 | SkDEBUGFAIL("unsupported"); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 170 | } |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 171 | return surface; |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 172 | } |
| 173 | |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 174 | #if SK_SUPPORT_GPU |
| 175 | GrContextFactory gContextFactory; |
| 176 | typedef GrContextFactory::GLContextType GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 177 | static const GLContextType kNative = GrContextFactory::kNative_GLContextType; |
commit-bot@chromium.org | e898957 | 2014-01-26 20:51:00 +0000 | [diff] [blame] | 178 | static const GLContextType kNVPR = GrContextFactory::kNVPR_GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 179 | #if SK_ANGLE |
| 180 | static const GLContextType kANGLE = GrContextFactory::kANGLE_GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 181 | #endif |
| 182 | static const GLContextType kDebug = GrContextFactory::kDebug_GLContextType; |
| 183 | static const GLContextType kNull = GrContextFactory::kNull_GLContextType; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 184 | #else |
| 185 | typedef int GLContextType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 186 | static const GLContextType kNative = 0, kANGLE = 0, kDebug = 0, kNull = 0; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 187 | #endif |
| 188 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 189 | #ifdef SK_DEBUG |
| 190 | static const bool kIsDebug = true; |
| 191 | #else |
| 192 | static const bool kIsDebug = false; |
| 193 | #endif |
| 194 | |
| 195 | static const struct Config { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 196 | SkColorType fColorType; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 197 | const char* name; |
| 198 | int sampleCount; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 199 | Benchmark::Backend backend; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 200 | GLContextType contextType; |
| 201 | bool runByDefault; |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 202 | } gConfigs[] = { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 203 | { kN32_SkColorType, "NONRENDERING", 0, Benchmark::kNonRendering_Backend, kNative, true}, |
| 204 | { kN32_SkColorType, "8888", 0, Benchmark::kRaster_Backend, kNative, true}, |
| 205 | { kRGB_565_SkColorType, "565", 0, Benchmark::kRaster_Backend, kNative, true}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 206 | #if SK_SUPPORT_GPU |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 207 | { kN32_SkColorType, "GPU", 0, Benchmark::kGPU_Backend, kNative, true}, |
| 208 | { kN32_SkColorType, "MSAA4", 4, Benchmark::kGPU_Backend, kNative, false}, |
| 209 | { kN32_SkColorType, "MSAA16", 16, Benchmark::kGPU_Backend, kNative, false}, |
| 210 | { kN32_SkColorType, "NVPRMSAA4", 4, Benchmark::kGPU_Backend, kNVPR, true}, |
| 211 | { kN32_SkColorType, "NVPRMSAA16", 16, Benchmark::kGPU_Backend, kNVPR, false}, |
robertphillips@google.com | d3b9fbb | 2012-03-28 16:19:11 +0000 | [diff] [blame] | 212 | #if SK_ANGLE |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 213 | { kN32_SkColorType, "ANGLE", 0, Benchmark::kGPU_Backend, kANGLE, true}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 214 | #endif // SK_ANGLE |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 215 | { kN32_SkColorType, "Debug", 0, Benchmark::kGPU_Backend, kDebug, kIsDebug}, |
| 216 | { kN32_SkColorType, "NULLGPU", 0, Benchmark::kGPU_Backend, kNull, true}, |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 217 | #endif // SK_SUPPORT_GPU |
reed@android.com | 4bc1983 | 2009-01-19 20:08:35 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 220 | DEFINE_string(outDir, "", "If given, image of each bench will be put in outDir."); |
| 221 | DEFINE_string(timers, "cg", "Timers to display. " |
| 222 | "Options: w(all) W(all, truncated) c(pu) C(pu, truncated) g(pu)"); |
reed@android.com | 4c7d3d6 | 2009-01-21 03:15:13 +0000 | [diff] [blame] | 223 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 224 | DEFINE_bool(rotate, false, "Rotate canvas before bench run?"); |
| 225 | DEFINE_bool(scale, false, "Scale canvas before bench run?"); |
| 226 | DEFINE_bool(clip, false, "Clip canvas before bench run?"); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 227 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 228 | DEFINE_bool(forceAA, true, "Force anti-aliasing?"); |
| 229 | DEFINE_bool(forceFilter, false, "Force bitmap filtering?"); |
| 230 | DEFINE_string(forceDither, "default", "Force dithering: true, false, or default?"); |
| 231 | DEFINE_bool(forceBlend, false, "Force alpha blending?"); |
| 232 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 233 | DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" " |
| 234 | "forces OpenGL API. Using \"gles\" forces OpenGL ES API. " |
| 235 | "Defaults to empty string, which selects the API native to the " |
| 236 | "system."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 237 | DEFINE_int32(gpuCacheBytes, -1, "GPU cache size limit in bytes. 0 to disable cache."); |
| 238 | DEFINE_int32(gpuCacheCount, -1, "GPU cache size limit in object count. 0 to disable cache."); |
| 239 | |
bsalomon | 6945618 | 2014-07-07 10:46:58 -0700 | [diff] [blame^] | 240 | DEFINE_bool(gpu, true, "Allows GPU configs to be run. Applied after --configs."); |
| 241 | DEFINE_bool(cpu, true, "Allows non-GPU configs to be run. Applied after --config."); |
| 242 | |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 243 | DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 244 | DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n" |
| 245 | "Multiple matches may be separated by spaces.\n" |
| 246 | "~ causes a matching test to always be skipped\n" |
| 247 | "^ requires the start of the test to match\n" |
| 248 | "$ requires the end of the test to match\n" |
| 249 | "^ and $ requires an exact match\n" |
| 250 | "If a test does not match any list entry,\n" |
| 251 | "it is skipped unless some list entry starts with ~\n"); |
| 252 | DEFINE_string(mode, "normal", |
| 253 | "normal: draw to a normal canvas;\n" |
| 254 | "deferred: draw to a deferred canvas;\n" |
| 255 | "deferredSilent: deferred with silent playback;\n" |
| 256 | "record: draw to an SkPicture;\n" |
| 257 | "picturerecord: draw from an SkPicture to an SkPicture.\n"); |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 258 | DEFINE_string(config, kDefaultsConfigStr, |
| 259 | "Run configs given. By default, runs the configs marked \"runByDefault\" in gConfigs."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 260 | DEFINE_string(logFile, "", "Also write stdout here."); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 261 | DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run."); |
borenet | 332600f | 2014-06-24 12:40:01 -0700 | [diff] [blame] | 262 | DEFINE_int32(maxMs, 1000, "Longest time we'll allow a benchmark to run."); |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 263 | DEFINE_bool(runOnce, kIsDebug, "Run each bench exactly once and don't report timings."); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 264 | DEFINE_double(error, 0.01, |
| 265 | "Ratio of subsequent bench measurements must drop within 1±error to converge."); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 266 | DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops."); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 267 | DEFINE_bool2(verbose, v, false, "Print more."); |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 268 | DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format."); |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 269 | DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done."); |
| 270 | |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 271 | // Has this bench converged? First arguments are milliseconds / loop iteration, |
| 272 | // last is overall runtime in milliseconds. |
| 273 | static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) { |
| 274 | if (currRaw < FLAGS_minMs) { |
| 275 | return false; |
| 276 | } |
| 277 | const double low = 1 - FLAGS_error, high = 1 + FLAGS_error; |
| 278 | const double ratio = currPerLoop / prevPerLoop; |
| 279 | return low < ratio && ratio < high; |
| 280 | } |
tomhudson@google.com | 86bb9b7 | 2012-04-03 13:28:57 +0000 | [diff] [blame] | 281 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 282 | int tool_main(int argc, char** argv); |
| 283 | int tool_main(int argc, char** argv) { |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 284 | SetupCrashHandler(); |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 285 | SkCommandLineFlags::Parse(argc, argv); |
bsalomon@google.com | 4e23068 | 2013-01-15 20:37:04 +0000 | [diff] [blame] | 286 | #if SK_ENABLE_INST_COUNT |
commit-bot@chromium.org | 6dda827 | 2014-01-23 17:21:19 +0000 | [diff] [blame] | 287 | if (FLAGS_leaks) { |
| 288 | gPrintInstCount = true; |
| 289 | } |
bsalomon@google.com | 65a87cc | 2012-08-14 13:15:44 +0000 | [diff] [blame] | 290 | #endif |
reed@android.com | 3a859a0 | 2009-01-28 00:56:29 +0000 | [diff] [blame] | 291 | SkAutoGraphics ag; |
bsalomon@google.com | 65a87cc | 2012-08-14 13:15:44 +0000 | [diff] [blame] | 292 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 293 | // First, parse some flags. |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 294 | BenchLogger logger; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 295 | if (FLAGS_logFile.count()) { |
| 296 | logger.SetLogFile(FLAGS_logFile[0]); |
| 297 | } |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 298 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 299 | LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]); |
| 300 | MultiResultsWriter writer; |
| 301 | writer.add(&logWriter); |
commit-bot@chromium.org | 61744ec | 2014-05-16 13:15:41 +0000 | [diff] [blame] | 302 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 303 | SkAutoTDelete<JSONResultsWriter> jsonWriter; |
| 304 | if (FLAGS_outResultsFile.count()) { |
| 305 | jsonWriter.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0]))); |
| 306 | writer.add(jsonWriter.get()); |
| 307 | } |
commit-bot@chromium.org | 61744ec | 2014-05-16 13:15:41 +0000 | [diff] [blame] | 308 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 309 | // Instantiate after all the writers have been added to writer so that we |
| 310 | // call close() before their destructors are called on the way out. |
| 311 | CallEnd<MultiResultsWriter> ender(writer); |
| 312 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 313 | const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF; |
| 314 | SkTriState::State dither = SkTriState::kDefault; |
| 315 | for (size_t i = 0; i < 3; i++) { |
| 316 | if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) { |
| 317 | dither = static_cast<SkTriState::State>(i); |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 320 | |
| 321 | BenchMode benchMode = kNormal_BenchMode; |
| 322 | for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) { |
| 323 | if (strcmp(FLAGS_mode[0], BenchMode_Name[i]) == 0) { |
| 324 | benchMode = static_cast<BenchMode>(i); |
| 325 | } |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 326 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 327 | |
| 328 | SkTDArray<int> configs; |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 329 | bool runDefaultConfigs = false; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 330 | // Try user-given configs first. |
| 331 | for (int i = 0; i < FLAGS_config.count(); i++) { |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 332 | for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++j) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 333 | if (0 == strcmp(FLAGS_config[i], gConfigs[j].name)) { |
| 334 | *configs.append() = j; |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 335 | } else if (0 == strcmp(FLAGS_config[i], kDefaultsConfigStr)) { |
| 336 | runDefaultConfigs = true; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 337 | } |
| 338 | } |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 339 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 340 | // If there weren't any, fill in with defaults. |
borenet@google.com | 4e061d3 | 2013-09-16 19:12:19 +0000 | [diff] [blame] | 341 | if (runDefaultConfigs) { |
robertphillips@google.com | e9cd27d | 2013-10-16 17:48:11 +0000 | [diff] [blame] | 342 | for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 343 | if (gConfigs[i].runByDefault) { |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 344 | *configs.append() = i; |
| 345 | } |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 346 | } |
| 347 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 348 | // Filter out things we can't run. |
| 349 | if (kNormal_BenchMode != benchMode) { |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 350 | // Non-rendering configs only run in normal mode |
| 351 | for (int i = 0; i < configs.count(); ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 352 | const Config& config = gConfigs[configs[i]]; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 353 | if (Benchmark::kNonRendering_Backend == config.backend) { |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 354 | configs.remove(i, 1); |
| 355 | --i; |
| 356 | } |
| 357 | } |
| 358 | } |
bsalomon | 6945618 | 2014-07-07 10:46:58 -0700 | [diff] [blame^] | 359 | // Apply the gpu/cpu only flags |
| 360 | for (int i = 0; i < configs.count(); ++i) { |
| 361 | const Config& config = gConfigs[configs[i]]; |
| 362 | if (config.backend == Benchmark::kGPU_Backend) { |
| 363 | if (!FLAGS_gpu) { |
| 364 | configs.remove(i, 1); |
| 365 | --i; |
| 366 | } |
| 367 | } else if (!FLAGS_cpu) { |
| 368 | configs.remove(i, 1); |
| 369 | --i; |
| 370 | } |
| 371 | } |
scroggo@google.com | 111fd11 | 2013-09-25 21:42:12 +0000 | [diff] [blame] | 372 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 373 | #if SK_SUPPORT_GPU |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 374 | GrGLStandard gpuAPI = kNone_GrGLStandard; |
| 375 | if (1 == FLAGS_gpuAPI.count()) { |
| 376 | if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) { |
| 377 | gpuAPI = kGL_GrGLStandard; |
| 378 | } else if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) { |
| 379 | gpuAPI = kGLES_GrGLStandard; |
| 380 | } else { |
| 381 | SkDebugf("Selected gpu API could not be used. Using the default.\n"); |
| 382 | } |
| 383 | } else if (FLAGS_gpuAPI.count() > 1) { |
| 384 | SkDebugf("Selected gpu API could not be used. Using the default.\n"); |
| 385 | } |
| 386 | |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 387 | for (int i = 0; i < configs.count(); ++i) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 388 | const Config& config = gConfigs[configs[i]]; |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 389 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 390 | if (Benchmark::kGPU_Backend == config.backend) { |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 391 | GrContext* context = gContextFactory.get(config.contextType, gpuAPI); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 392 | if (NULL == context) { |
commit-bot@chromium.org | 0f298cc | 2014-04-30 15:54:29 +0000 | [diff] [blame] | 393 | SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n", |
| 394 | config.name); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 395 | configs.remove(i); |
| 396 | --i; |
| 397 | continue; |
| 398 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 399 | if (config.sampleCount > context->getMaxSampleCount()){ |
commit-bot@chromium.org | 0f298cc | 2014-04-30 15:54:29 +0000 | [diff] [blame] | 400 | SkDebugf( |
| 401 | "Sample count (%d) for config %s is not supported. Config will be skipped.\n", |
| 402 | config.sampleCount, config.name); |
bsalomon@google.com | 8a70eef | 2013-03-19 13:58:55 +0000 | [diff] [blame] | 403 | configs.remove(i); |
| 404 | --i; |
| 405 | continue; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | #endif |
| 410 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 411 | // All flags should be parsed now. Report our settings. |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 412 | if (FLAGS_runOnce) { |
| 413 | logger.logError("bench was run with --runOnce, so we're going to hide the times." |
| 414 | " It's for your own good!\n"); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 415 | } |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 416 | writer.option("mode", FLAGS_mode[0]); |
| 417 | writer.option("alpha", SkStringPrintf("0x%02X", alpha).c_str()); |
| 418 | writer.option("antialias", SkStringPrintf("%d", FLAGS_forceAA).c_str()); |
| 419 | writer.option("filter", SkStringPrintf("%d", FLAGS_forceFilter).c_str()); |
| 420 | writer.option("dither", SkTriState::Name[dither]); |
| 421 | |
| 422 | writer.option("rotate", SkStringPrintf("%d", FLAGS_rotate).c_str()); |
| 423 | writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str()); |
| 424 | writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str()); |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 425 | |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 426 | #if defined(SK_BUILD_FOR_WIN32) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 427 | writer.option("system", "WIN32"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 428 | #elif defined(SK_BUILD_FOR_MAC) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 429 | writer.option("system", "MAC"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 430 | #elif defined(SK_BUILD_FOR_ANDROID) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 431 | writer.option("system", "ANDROID"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 432 | #elif defined(SK_BUILD_FOR_UNIX) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 433 | writer.option("system", "UNIX"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 434 | #else |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 435 | writer.option("system", "other"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 436 | #endif |
| 437 | |
| 438 | #if defined(SK_DEBUG) |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 439 | writer.option("build", "DEBUG"); |
| 440 | #else |
| 441 | writer.option("build", "RELEASE"); |
bungeman@google.com | a5d4841 | 2011-06-15 17:25:46 +0000 | [diff] [blame] | 442 | #endif |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 443 | |
| 444 | // Set texture cache limits if non-default. |
bsalomon@google.com | 5c90e29 | 2013-02-22 19:17:13 +0000 | [diff] [blame] | 445 | for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) { |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 446 | #if SK_SUPPORT_GPU |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 447 | const Config& config = gConfigs[i]; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 448 | if (Benchmark::kGPU_Backend != config.backend) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 449 | continue; |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 450 | } |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 451 | GrContext* context = gContextFactory.get(config.contextType, gpuAPI); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 452 | if (NULL == context) { |
| 453 | continue; |
| 454 | } |
| 455 | |
| 456 | size_t bytes; |
| 457 | int count; |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 458 | context->getResourceCacheLimits(&count, &bytes); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 459 | if (-1 != FLAGS_gpuCacheBytes) { |
| 460 | bytes = static_cast<size_t>(FLAGS_gpuCacheBytes); |
| 461 | } |
| 462 | if (-1 != FLAGS_gpuCacheCount) { |
| 463 | count = FLAGS_gpuCacheCount; |
| 464 | } |
commit-bot@chromium.org | 95c2003 | 2014-05-09 14:29:32 +0000 | [diff] [blame] | 465 | context->setResourceCacheLimits(count, bytes); |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 466 | #endif |
| 467 | } |
bsalomon@google.com | 7491372 | 2011-10-27 20:44:19 +0000 | [diff] [blame] | 468 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 469 | // Run each bench in each configuration it supports and we asked for. |
| 470 | Iter iter; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 471 | Benchmark* bench; |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 472 | while ((bench = iter.next()) != NULL) { |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 473 | SkAutoTUnref<Benchmark> benchUnref(bench); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 474 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) { |
reed@android.com | b398fe8 | 2009-01-07 11:47:57 +0000 | [diff] [blame] | 475 | continue; |
| 476 | } |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 477 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 478 | bench->setForceAlpha(alpha); |
| 479 | bench->setForceAA(FLAGS_forceAA); |
| 480 | bench->setForceFilter(FLAGS_forceFilter); |
| 481 | bench->setDither(dither); |
mtklein | 683e906 | 2014-06-18 07:15:48 -0700 | [diff] [blame] | 482 | bench->preDraw(); |
bsalomon@google.com | 30e6d2c | 2012-08-13 14:03:31 +0000 | [diff] [blame] | 483 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 484 | bool loggedBenchName = false; |
| 485 | for (int i = 0; i < configs.count(); ++i) { |
| 486 | const int configIndex = configs[i]; |
| 487 | const Config& config = gConfigs[configIndex]; |
tomhudson@google.com | 13eaaaa | 2012-04-16 18:00:40 +0000 | [diff] [blame] | 488 | |
commit-bot@chromium.org | 644629c | 2013-11-21 06:21:58 +0000 | [diff] [blame] | 489 | if (!bench->isSuitableFor(config.backend)) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 490 | continue; |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 491 | } |
| 492 | |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 493 | GrContext* context = NULL; |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 494 | #if SK_SUPPORT_GPU |
sugoi@google.com | 9c55f80 | 2013-03-07 20:52:59 +0000 | [diff] [blame] | 495 | SkGLContextHelper* glContext = NULL; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 496 | if (Benchmark::kGPU_Backend == config.backend) { |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 497 | context = gContextFactory.get(config.contextType, gpuAPI); |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 498 | if (NULL == context) { |
| 499 | continue; |
| 500 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 501 | glContext = gContextFactory.getGLContext(config.contextType); |
mike@reedtribe.org | a9015f8 | 2011-05-17 02:25:05 +0000 | [diff] [blame] | 502 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 503 | #endif |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 504 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 505 | SkAutoTUnref<SkCanvas> canvas; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 506 | SkAutoTUnref<SkPicture> recordFrom; |
| 507 | SkPictureRecorder recorderTo; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 508 | const SkIPoint dim = bench->getSize(); |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 509 | |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 510 | SkAutoTUnref<SkSurface> surface; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 511 | if (Benchmark::kNonRendering_Backend != config.backend) { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 512 | surface.reset(make_surface(config.fColorType, |
| 513 | dim, |
| 514 | config.backend, |
| 515 | config.sampleCount, |
| 516 | context)); |
| 517 | if (!surface.get()) { |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 518 | logger.logError(SkStringPrintf( |
| 519 | "Device creation failure for config %s. Will skip.\n", config.name)); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 520 | continue; |
keyar@chromium.org | fdd909c | 2012-07-20 23:03:42 +0000 | [diff] [blame] | 521 | } |
junov@chromium.org | fb10389 | 2012-09-20 19:35:43 +0000 | [diff] [blame] | 522 | |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 523 | switch(benchMode) { |
| 524 | case kDeferredSilent_BenchMode: |
| 525 | case kDeferred_BenchMode: |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 526 | canvas.reset(SkDeferredCanvas::Create(surface.get())); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 527 | break; |
| 528 | case kRecord_BenchMode: |
robertphillips | 9f1c241 | 2014-06-09 06:25:34 -0700 | [diff] [blame] | 529 | canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY))); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 530 | break; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 531 | case kPictureRecord_BenchMode: { |
| 532 | SkPictureRecorder recorderFrom; |
robertphillips | 9f1c241 | 2014-06-09 06:25:34 -0700 | [diff] [blame] | 533 | bench->draw(1, recorderFrom.beginRecording(dim.fX, dim.fY)); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 534 | recordFrom.reset(recorderFrom.endRecording()); |
robertphillips | 9f1c241 | 2014-06-09 06:25:34 -0700 | [diff] [blame] | 535 | canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY))); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 536 | break; |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 537 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 538 | case kNormal_BenchMode: |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 539 | canvas.reset(SkRef(surface->getCanvas())); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 540 | break; |
| 541 | default: |
| 542 | SkASSERT(false); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | if (NULL != canvas) { |
| 547 | canvas->clear(SK_ColorWHITE); |
skia.committer@gmail.com | 5199701 | 2014-04-14 03:04:57 +0000 | [diff] [blame] | 548 | if (FLAGS_clip) { |
| 549 | perform_clip(canvas, dim.fX, dim.fY); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 550 | } |
skia.committer@gmail.com | 5199701 | 2014-04-14 03:04:57 +0000 | [diff] [blame] | 551 | if (FLAGS_scale) { |
| 552 | perform_scale(canvas, dim.fX, dim.fY); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 553 | } |
skia.committer@gmail.com | 5199701 | 2014-04-14 03:04:57 +0000 | [diff] [blame] | 554 | if (FLAGS_rotate) { |
| 555 | perform_rotate(canvas, dim.fX, dim.fY); |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 556 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | if (!loggedBenchName) { |
| 560 | loggedBenchName = true; |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 561 | writer.bench(bench->getName(), dim.fX, dim.fY); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | #if SK_SUPPORT_GPU |
| 565 | SkGLContextHelper* contextHelper = NULL; |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 566 | if (Benchmark::kGPU_Backend == config.backend) { |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 567 | contextHelper = gContextFactory.getGLContext(config.contextType); |
| 568 | } |
mtklein | 9ac68ee | 2014-06-20 11:29:20 -0700 | [diff] [blame] | 569 | Timer timer(contextHelper); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 570 | #else |
mtklein | 9ac68ee | 2014-06-20 11:29:20 -0700 | [diff] [blame] | 571 | Timer timer; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 572 | #endif |
| 573 | |
mtklein@google.com | 9ef1d21 | 2013-09-13 20:39:50 +0000 | [diff] [blame] | 574 | double previous = std::numeric_limits<double>::infinity(); |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 575 | bool converged = false; |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 576 | |
| 577 | // variables used to compute loopsPerFrame |
| 578 | double frameIntervalTime = 0.0f; |
| 579 | int frameIntervalTotalLoops = 0; |
| 580 | |
| 581 | bool frameIntervalComputed = false; |
| 582 | int loopsPerFrame = 0; |
| 583 | int loopsPerIter = 0; |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 584 | if (FLAGS_verbose) { SkDebugf("%s %s: ", bench->getName(), config.name); } |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 585 | if (!FLAGS_dryRun) { |
| 586 | do { |
| 587 | // Ramp up 1 -> 2 -> 4 -> 8 -> 16 -> ... -> ~1 billion. |
| 588 | loopsPerIter = (loopsPerIter == 0) ? 1 : loopsPerIter * 2; |
| 589 | if (loopsPerIter >= (1<<30) || timer.fWall > FLAGS_maxMs) { |
| 590 | // If you find it takes more than a billion loops to get up to 20ms of runtime, |
| 591 | // you've got a computer clocked at several THz or have a broken benchmark. ;) |
| 592 | // "1B ought to be enough for anybody." |
| 593 | logger.logError(SkStringPrintf( |
| 594 | "\nCan't get %s %s to converge in %dms (%d loops)", |
| 595 | bench->getName(), config.name, FLAGS_maxMs, loopsPerIter)); |
| 596 | break; |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 597 | } |
| 598 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 599 | if ((benchMode == kRecord_BenchMode || benchMode == kPictureRecord_BenchMode)) { |
| 600 | // Clear the recorded commands so that they do not accumulate. |
robertphillips | 9f1c241 | 2014-06-09 06:25:34 -0700 | [diff] [blame] | 601 | canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY))); |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 602 | } |
| 603 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 604 | timer.start(); |
| 605 | // Inner loop that allows us to break the run into smaller |
| 606 | // chunks (e.g. frames). This is especially useful for the GPU |
| 607 | // as we can flush and/or swap buffers to keep the GPU from |
| 608 | // queuing up too much work. |
| 609 | for (int loopCount = loopsPerIter; loopCount > 0; ) { |
| 610 | // Save and restore around each call to draw() to guarantee a pristine canvas. |
| 611 | SkAutoCanvasRestore saveRestore(canvas, true/*also save*/); |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 612 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 613 | int loops; |
| 614 | if (frameIntervalComputed && loopCount > loopsPerFrame) { |
| 615 | loops = loopsPerFrame; |
| 616 | loopCount -= loopsPerFrame; |
| 617 | } else { |
| 618 | loops = loopCount; |
| 619 | loopCount = 0; |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 620 | } |
djsollen@google.com | dcfed6c | 2013-10-10 18:48:27 +0000 | [diff] [blame] | 621 | |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 622 | if (benchMode == kPictureRecord_BenchMode) { |
robertphillips@google.com | 84b18c7 | 2014-04-13 19:09:42 +0000 | [diff] [blame] | 623 | recordFrom->draw(canvas); |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 624 | } else { |
| 625 | bench->draw(loops, canvas); |
| 626 | } |
| 627 | |
| 628 | if (kDeferredSilent_BenchMode == benchMode) { |
| 629 | static_cast<SkDeferredCanvas*>(canvas.get())->silentFlush(); |
| 630 | } else if (NULL != canvas) { |
| 631 | canvas->flush(); |
| 632 | } |
| 633 | |
| 634 | #if SK_SUPPORT_GPU |
| 635 | // swap drawing buffers on each frame to prevent the GPU |
| 636 | // from queuing up too much work |
| 637 | if (NULL != glContext) { |
| 638 | glContext->swapBuffers(); |
| 639 | } |
| 640 | #endif |
| 641 | } |
| 642 | |
| 643 | |
| 644 | |
| 645 | // Stop truncated timers before GL calls complete, and stop the full timers after. |
| 646 | timer.truncatedEnd(); |
| 647 | #if SK_SUPPORT_GPU |
| 648 | if (NULL != glContext) { |
| 649 | context->flush(); |
| 650 | SK_GL(*glContext, Finish()); |
| 651 | } |
| 652 | #endif |
| 653 | timer.end(); |
| 654 | |
| 655 | // setup the frame interval for subsequent iterations |
| 656 | if (!frameIntervalComputed) { |
| 657 | frameIntervalTime += timer.fWall; |
| 658 | frameIntervalTotalLoops += loopsPerIter; |
| 659 | if (frameIntervalTime >= FLAGS_minMs) { |
| 660 | frameIntervalComputed = true; |
| 661 | loopsPerFrame = |
| 662 | (int)(((double)frameIntervalTotalLoops / frameIntervalTime) * FLAGS_minMs); |
| 663 | if (loopsPerFrame < 1) { |
| 664 | loopsPerFrame = 1; |
| 665 | } |
| 666 | // SkDebugf(" %s has %d loops in %f ms (normalized to %d)\n", |
| 667 | // bench->getName(), frameIntervalTotalLoops, |
| 668 | // timer.fWall, loopsPerFrame); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | const double current = timer.fWall / loopsPerIter; |
| 673 | if (FLAGS_verbose && current > previous) { SkDebugf("↑"); } |
| 674 | if (FLAGS_verbose) { SkDebugf("%.3g ", current); } |
| 675 | converged = HasConverged(previous, current, timer.fWall); |
| 676 | previous = current; |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 677 | } while (!FLAGS_runOnce && !converged); |
commit-bot@chromium.org | 56b7a6d | 2014-03-13 16:22:00 +0000 | [diff] [blame] | 678 | } |
mtklein@google.com | dbd41c8 | 2013-09-13 20:11:09 +0000 | [diff] [blame] | 679 | if (FLAGS_verbose) { SkDebugf("\n"); } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 680 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 681 | if (!FLAGS_dryRun && FLAGS_outDir.count() && Benchmark::kNonRendering_Backend != config.backend) { |
reed@google.com | 1bc6c6a | 2014-02-04 14:02:44 +0000 | [diff] [blame] | 682 | SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
| 683 | if (image.get()) { |
| 684 | saveFile(bench->getName(), config.name, FLAGS_outDir[0], |
| 685 | image); |
| 686 | } |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 687 | } |
| 688 | |
commit-bot@chromium.org | 4bbe2e5 | 2014-04-21 21:12:32 +0000 | [diff] [blame] | 689 | if (FLAGS_runOnce) { |
| 690 | // Let's not mislead ourselves by looking at Debug build or single iteration bench times! |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 691 | continue; |
| 692 | } |
| 693 | |
| 694 | // Normalize to ms per 1000 iterations. |
djsollen@google.com | 70de4da | 2013-10-10 17:33:39 +0000 | [diff] [blame] | 695 | const double normalize = 1000.0 / loopsPerIter; |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 696 | const struct { char shortName; const char* longName; double ms; } times[] = { |
| 697 | {'w', "msecs", normalize * timer.fWall}, |
| 698 | {'W', "Wmsecs", normalize * timer.fTruncatedWall}, |
| 699 | {'c', "cmsecs", normalize * timer.fCpu}, |
| 700 | {'C', "Cmsecs", normalize * timer.fTruncatedCpu}, |
| 701 | {'g', "gmsecs", normalize * timer.fGpu}, |
| 702 | }; |
| 703 | |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 704 | writer.config(config.name); |
mtklein@google.com | c289743 | 2013-09-10 19:23:38 +0000 | [diff] [blame] | 705 | for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) { |
| 706 | if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) { |
commit-bot@chromium.org | e3bb3bc | 2013-12-03 18:16:48 +0000 | [diff] [blame] | 707 | writer.timer(times[i].longName, times[i].ms); |
commit-bot@chromium.org | 7495f59 | 2013-06-03 19:31:07 +0000 | [diff] [blame] | 708 | } |
reed@google.com | 25df888 | 2011-07-14 19:03:58 +0000 | [diff] [blame] | 709 | } |
bsalomon@google.com | 604a56a | 2013-03-15 15:42:15 +0000 | [diff] [blame] | 710 | } |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 711 | } |
bsalomon@google.com | cf8fb1f | 2012-08-02 14:03:32 +0000 | [diff] [blame] | 712 | #if SK_SUPPORT_GPU |
bsalomon@google.com | cb26535 | 2013-02-22 16:13:16 +0000 | [diff] [blame] | 713 | gContextFactory.destroyContexts(); |
robertphillips@google.com | 9d59420 | 2012-09-13 14:05:00 +0000 | [diff] [blame] | 714 | #endif |
reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame] | 715 | return 0; |
| 716 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 717 | |
borenet@google.com | 7158e6a | 2012-11-01 17:43:44 +0000 | [diff] [blame] | 718 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 719 | int main(int argc, char * const argv[]) { |
| 720 | return tool_main(argc, (char**) argv); |
| 721 | } |
| 722 | #endif |