blob: 9c5f0e9bd7af59868d3892e4910a7b32ced35f4f [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
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.com971d0c82011-08-19 17:22:05 +00007
tfarinaf168b862014-06-19 12:32:29 -07008#include "BenchLogger.h"
tfarinaf168b862014-06-19 12:32:29 -07009#include "Benchmark.h"
mtklein30e6e2a2014-06-18 11:44:15 -070010#include "CrashHandler.h"
tfarinaf168b862014-06-19 12:32:29 -070011#include "GMBench.h"
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +000012#include "ResultsWriter.h"
reed@android.combd700c32009-01-05 03:34:50 +000013#include "SkCanvas.h"
mtklein@google.com78d03792013-09-10 19:42:07 +000014#include "SkColorPriv.h"
sglez@google.com586db932013-07-24 17:24:23 +000015#include "SkCommandLineFlags.h"
reed@google.com1bc6c6a2014-02-04 14:02:44 +000016#include "SkData.h"
bsalomon@google.com82a7bfc2012-04-16 19:11:17 +000017#include "SkDeferredCanvas.h"
reed@android.com3a859a02009-01-28 00:56:29 +000018#include "SkGraphics.h"
reed@android.comb398fe82009-01-07 11:47:57 +000019#include "SkImageEncoder.h"
mtklein@google.comc2897432013-09-10 19:23:38 +000020#include "SkOSFile.h"
reed@android.com6c924ad2009-03-31 03:48:49 +000021#include "SkPicture.h"
robertphillips@google.com770963f2014-04-18 18:04:41 +000022#include "SkPictureRecorder.h"
reed@android.combd700c32009-01-05 03:34:50 +000023#include "SkString.h"
reed@google.com1bc6c6a2014-02-04 14:02:44 +000024#include "SkSurface.h"
mtklein9ac68ee2014-06-20 11:29:20 -070025#include "Timer.h"
reed@android.com29348cb2009-08-04 18:17:15 +000026
djsollen@google.comdb490e92013-11-20 13:15:40 +000027#if SK_SUPPORT_GPU
28#include "GrContext.h"
29#include "GrContextFactory.h"
30#include "GrRenderTarget.h"
djsollen@google.comdb490e92013-11-20 13:15:40 +000031#include "gl/GrGLDefines.h"
32#else
33class GrContext;
34#endif // SK_SUPPORT_GPU
35
mtklein@google.com9ef1d212013-09-13 20:39:50 +000036#include <limits>
37
mtklein@google.comc2897432013-09-10 19:23:38 +000038enum BenchMode {
39 kNormal_BenchMode,
40 kDeferred_BenchMode,
41 kDeferredSilent_BenchMode,
42 kRecord_BenchMode,
43 kPictureRecord_BenchMode
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +000044};
mtklein@google.comdbd41c82013-09-13 20:11:09 +000045const char* BenchMode_Name[] = {
46 "normal", "deferred", "deferredSilent", "record", "picturerecord"
47};
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000048
borenet@google.com4e061d32013-09-16 19:12:19 +000049static const char kDefaultsConfigStr[] = "defaults";
50
kkinnunen80549fc2014-06-30 06:36:31 -070051#if SK_SUPPORT_GPU
52static const char kGpuAPINameGL[] = "gl";
53static const char kGpuAPINameGLES[] = "gles";
54#endif
55
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +000056///////////////////////////////////////////////////////////////////////////////
57
reed@android.combd700c32009-01-05 03:34:50 +000058class Iter {
59public:
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000060 Iter() : fBenches(BenchRegistry::Head()), fGMs(skiagm::GMRegistry::Head()) {}
rmistry@google.comfbfcd562012-08-23 18:09:54 +000061
tfarinaf168b862014-06-19 12:32:29 -070062 Benchmark* next() {
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000063 if (fBenches) {
64 BenchRegistry::Factory f = fBenches->factory();
65 fBenches = fBenches->next();
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000066 return (*f)(NULL);
reed@android.combd700c32009-01-05 03:34:50 +000067 }
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000068
69 while (fGMs) {
70 SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL));
71 fGMs = fGMs->next();
72 if (gm->getFlags() & skiagm::GM::kAsBench_Flag) {
tfarinaf168b862014-06-19 12:32:29 -070073 return SkNEW_ARGS(GMBench, (gm.detach()));
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000074 }
75 }
76
reed@android.combd700c32009-01-05 03:34:50 +000077 return NULL;
78 }
bungeman@google.comd1a416a2011-05-18 18:37:07 +000079
reed@android.combd700c32009-01-05 03:34:50 +000080private:
commit-bot@chromium.org575d9cd2014-02-24 23:25:49 +000081 const BenchRegistry* fBenches;
82 const skiagm::GMRegistry* fGMs;
reed@android.combd700c32009-01-05 03:34:50 +000083};
84
85static 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.com4c7d3d62009-01-21 03:15:13 +0000101static void saveFile(const char name[], const char config[], const char dir[],
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000102 const SkImage* image) {
103 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100));
104 if (NULL == data.get()) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000105 return;
106 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000107
mtklein@google.comc2897432013-09-10 19:23:38 +0000108 SkString filename;
109 make_filename(name, &filename);
110 filename.appendf("_%s.png", config);
tfarinaa8e2e152014-07-28 19:26:58 -0700111 SkString path = SkOSPath::Join(dir, filename.c_str());
mtklein@google.comc2897432013-09-10 19:23:38 +0000112 ::remove(path.c_str());
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000113
reed@google.comace13542014-02-06 22:00:58 +0000114 SkFILEWStream stream(path.c_str());
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000115 stream.write(data->data(), data->size());
reed@android.com4c7d3d62009-01-21 03:15:13 +0000116}
117
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000118static void perform_clip(SkCanvas* canvas, int w, int h) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000119 SkRect r;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000120
reed@android.com4c7d3d62009-01-21 03:15:13 +0000121 r.set(SkIntToScalar(10), SkIntToScalar(10),
122 SkIntToScalar(w*2/3), SkIntToScalar(h*2/3));
123 canvas->clipRect(r, SkRegion::kIntersect_Op);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000124
reed@android.com4c7d3d62009-01-21 03:15:13 +0000125 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.com84b18c72014-04-13 19:09:42 +0000130static void perform_rotate(SkCanvas* canvas, int w, int h) {
reed@android.com4c7d3d62009-01-21 03:15:13 +0000131 const SkScalar x = SkIntToScalar(w) / 2;
132 const SkScalar y = SkIntToScalar(h) / 2;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000133
reed@android.com4c7d3d62009-01-21 03:15:13 +0000134 canvas->translate(x, y);
135 canvas->rotate(SkIntToScalar(35));
136 canvas->translate(-x, -y);
137}
138
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000139static void perform_scale(SkCanvas* canvas, int w, int h) {
reed@android.com387359e2009-08-04 01:51:09 +0000140 const SkScalar x = SkIntToScalar(w) / 2;
141 const SkScalar y = SkIntToScalar(h) / 2;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000142
reed@android.com387359e2009-08-04 01:51:09 +0000143 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.com1bc6c6a2014-02-04 14:02:44 +0000149static SkSurface* make_surface(SkColorType colorType, const SkIPoint& size,
tfarinaf168b862014-06-19 12:32:29 -0700150 Benchmark::Backend backend, int sampleCount,
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000151 GrContext* context) {
152 SkSurface* surface = NULL;
153 SkImageInfo info = SkImageInfo::Make(size.fX, size.fY, colorType,
154 kPremul_SkAlphaType);
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000155
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000156 switch (backend) {
tfarinaf168b862014-06-19 12:32:29 -0700157 case Benchmark::kRaster_Backend:
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000158 surface = SkSurface::NewRaster(info);
159 surface->getCanvas()->clear(SK_ColorWHITE);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000160 break;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000161#if SK_SUPPORT_GPU
tfarinaf168b862014-06-19 12:32:29 -0700162 case Benchmark::kGPU_Backend: {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000163 surface = SkSurface::NewRenderTarget(context, info, sampleCount);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000164 break;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000165 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000166#endif
tfarinaf168b862014-06-19 12:32:29 -0700167 case Benchmark::kPDF_Backend:
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000168 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000169 SkDEBUGFAIL("unsupported");
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000170 }
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000171 return surface;
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000172}
173
bsalomon@google.comcb265352013-02-22 16:13:16 +0000174#if SK_SUPPORT_GPU
175GrContextFactory gContextFactory;
176typedef GrContextFactory::GLContextType GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000177static const GLContextType kNative = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orge8989572014-01-26 20:51:00 +0000178static const GLContextType kNVPR = GrContextFactory::kNVPR_GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000179#if SK_ANGLE
180static const GLContextType kANGLE = GrContextFactory::kANGLE_GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000181#endif
182static const GLContextType kDebug = GrContextFactory::kDebug_GLContextType;
183static const GLContextType kNull = GrContextFactory::kNull_GLContextType;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000184#else
185typedef int GLContextType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000186static const GLContextType kNative = 0, kANGLE = 0, kDebug = 0, kNull = 0;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000187#endif
188
mtklein@google.comc2897432013-09-10 19:23:38 +0000189#ifdef SK_DEBUG
190static const bool kIsDebug = true;
191#else
192static const bool kIsDebug = false;
193#endif
194
195static const struct Config {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000196 SkColorType fColorType;
mtklein@google.comc2897432013-09-10 19:23:38 +0000197 const char* name;
198 int sampleCount;
tfarinaf168b862014-06-19 12:32:29 -0700199 Benchmark::Backend backend;
mtklein@google.comc2897432013-09-10 19:23:38 +0000200 GLContextType contextType;
201 bool runByDefault;
reed@android.com4bc19832009-01-19 20:08:35 +0000202} gConfigs[] = {
tfarinaf168b862014-06-19 12:32:29 -0700203 { 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.comcf8fb1f2012-08-02 14:03:32 +0000206#if SK_SUPPORT_GPU
tfarinaf168b862014-06-19 12:32:29 -0700207 { 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.comd3b9fbb2012-03-28 16:19:11 +0000212#if SK_ANGLE
tfarinaf168b862014-06-19 12:32:29 -0700213 { kN32_SkColorType, "ANGLE", 0, Benchmark::kGPU_Backend, kANGLE, true},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000214#endif // SK_ANGLE
tfarinaf168b862014-06-19 12:32:29 -0700215 { kN32_SkColorType, "Debug", 0, Benchmark::kGPU_Backend, kDebug, kIsDebug},
216 { kN32_SkColorType, "NULLGPU", 0, Benchmark::kGPU_Backend, kNull, true},
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000217#endif // SK_SUPPORT_GPU
reed@android.com4bc19832009-01-19 20:08:35 +0000218};
219
mtklein@google.comc2897432013-09-10 19:23:38 +0000220DEFINE_string(outDir, "", "If given, image of each bench will be put in outDir.");
221DEFINE_string(timers, "cg", "Timers to display. "
222 "Options: w(all) W(all, truncated) c(pu) C(pu, truncated) g(pu)");
reed@android.com4c7d3d62009-01-21 03:15:13 +0000223
mtklein@google.comc2897432013-09-10 19:23:38 +0000224DEFINE_bool(rotate, false, "Rotate canvas before bench run?");
225DEFINE_bool(scale, false, "Scale canvas before bench run?");
226DEFINE_bool(clip, false, "Clip canvas before bench run?");
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000227
mtklein@google.comc2897432013-09-10 19:23:38 +0000228DEFINE_string(forceDither, "default", "Force dithering: true, false, or default?");
229DEFINE_bool(forceBlend, false, "Force alpha blending?");
230
kkinnunen80549fc2014-06-30 06:36:31 -0700231DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" "
232 "forces OpenGL API. Using \"gles\" forces OpenGL ES API. "
233 "Defaults to empty string, which selects the API native to the "
234 "system.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000235DEFINE_int32(gpuCacheBytes, -1, "GPU cache size limit in bytes. 0 to disable cache.");
236DEFINE_int32(gpuCacheCount, -1, "GPU cache size limit in object count. 0 to disable cache.");
237
bsalomon69456182014-07-07 10:46:58 -0700238DEFINE_bool(gpu, true, "Allows GPU configs to be run. Applied after --configs.");
239DEFINE_bool(cpu, true, "Allows non-GPU configs to be run. Applied after --config.");
240
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +0000241DEFINE_bool2(leaks, l, false, "show leaked ref cnt'd objects.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000242DEFINE_string(match, "", "[~][^]substring[$] [...] of test name to run.\n"
243 "Multiple matches may be separated by spaces.\n"
244 "~ causes a matching test to always be skipped\n"
245 "^ requires the start of the test to match\n"
246 "$ requires the end of the test to match\n"
247 "^ and $ requires an exact match\n"
248 "If a test does not match any list entry,\n"
249 "it is skipped unless some list entry starts with ~\n");
250DEFINE_string(mode, "normal",
251 "normal: draw to a normal canvas;\n"
252 "deferred: draw to a deferred canvas;\n"
253 "deferredSilent: deferred with silent playback;\n"
254 "record: draw to an SkPicture;\n"
255 "picturerecord: draw from an SkPicture to an SkPicture.\n");
borenet@google.com4e061d32013-09-16 19:12:19 +0000256DEFINE_string(config, kDefaultsConfigStr,
257 "Run configs given. By default, runs the configs marked \"runByDefault\" in gConfigs.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000258DEFINE_string(logFile, "", "Also write stdout here.");
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000259DEFINE_int32(minMs, 20, "Shortest time we'll allow a benchmark to run.");
borenet332600f2014-06-24 12:40:01 -0700260DEFINE_int32(maxMs, 1000, "Longest time we'll allow a benchmark to run.");
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000261DEFINE_bool(runOnce, kIsDebug, "Run each bench exactly once and don't report timings.");
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000262DEFINE_double(error, 0.01,
263 "Ratio of subsequent bench measurements must drop within 1±error to converge.");
mtklein@google.comc2897432013-09-10 19:23:38 +0000264DEFINE_string(timeFormat, "%9.2f", "Format to print results, in milliseconds per 1000 loops.");
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000265DEFINE_bool2(verbose, v, false, "Print more.");
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000266DEFINE_string(outResultsFile, "", "If given, the results will be written to the file in JSON format.");
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000267DEFINE_bool(dryRun, false, "Don't actually run the tests, just print what would have been done.");
268
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000269// Has this bench converged? First arguments are milliseconds / loop iteration,
270// last is overall runtime in milliseconds.
271static bool HasConverged(double prevPerLoop, double currPerLoop, double currRaw) {
272 if (currRaw < FLAGS_minMs) {
273 return false;
274 }
275 const double low = 1 - FLAGS_error, high = 1 + FLAGS_error;
276 const double ratio = currPerLoop / prevPerLoop;
277 return low < ratio && ratio < high;
278}
tomhudson@google.com86bb9b72012-04-03 13:28:57 +0000279
caryclark@google.com5987f582012-10-02 18:33:14 +0000280int tool_main(int argc, char** argv);
281int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -0700282 SetupCrashHandler();
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +0000283 SkCommandLineFlags::Parse(argc, argv);
bsalomon@google.com4e230682013-01-15 20:37:04 +0000284#if SK_ENABLE_INST_COUNT
commit-bot@chromium.org6dda8272014-01-23 17:21:19 +0000285 if (FLAGS_leaks) {
286 gPrintInstCount = true;
287 }
bsalomon@google.com65a87cc2012-08-14 13:15:44 +0000288#endif
reed@android.com3a859a02009-01-28 00:56:29 +0000289 SkAutoGraphics ag;
bsalomon@google.com65a87cc2012-08-14 13:15:44 +0000290
mtklein@google.comc2897432013-09-10 19:23:38 +0000291 // First, parse some flags.
tfarinaf168b862014-06-19 12:32:29 -0700292 BenchLogger logger;
mtklein@google.comc2897432013-09-10 19:23:38 +0000293 if (FLAGS_logFile.count()) {
294 logger.SetLogFile(FLAGS_logFile[0]);
295 }
scroggo@google.com9a412522012-09-07 15:21:18 +0000296
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000297 LoggerResultsWriter logWriter(logger, FLAGS_timeFormat[0]);
298 MultiResultsWriter writer;
299 writer.add(&logWriter);
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +0000300
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000301 SkAutoTDelete<JSONResultsWriter> jsonWriter;
302 if (FLAGS_outResultsFile.count()) {
303 jsonWriter.reset(SkNEW(JSONResultsWriter(FLAGS_outResultsFile[0])));
304 writer.add(jsonWriter.get());
305 }
commit-bot@chromium.org61744ec2014-05-16 13:15:41 +0000306
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000307 // Instantiate after all the writers have been added to writer so that we
308 // call close() before their destructors are called on the way out.
309 CallEnd<MultiResultsWriter> ender(writer);
310
mtklein@google.comc2897432013-09-10 19:23:38 +0000311 const uint8_t alpha = FLAGS_forceBlend ? 0x80 : 0xFF;
312 SkTriState::State dither = SkTriState::kDefault;
313 for (size_t i = 0; i < 3; i++) {
314 if (strcmp(SkTriState::Name[i], FLAGS_forceDither[0]) == 0) {
315 dither = static_cast<SkTriState::State>(i);
reed@android.comb398fe82009-01-07 11:47:57 +0000316 }
317 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000318
319 BenchMode benchMode = kNormal_BenchMode;
320 for (size_t i = 0; i < SK_ARRAY_COUNT(BenchMode_Name); i++) {
321 if (strcmp(FLAGS_mode[0], BenchMode_Name[i]) == 0) {
322 benchMode = static_cast<BenchMode>(i);
323 }
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +0000324 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000325
326 SkTDArray<int> configs;
borenet@google.com4e061d32013-09-16 19:12:19 +0000327 bool runDefaultConfigs = false;
mtklein@google.comc2897432013-09-10 19:23:38 +0000328 // Try user-given configs first.
329 for (int i = 0; i < FLAGS_config.count(); i++) {
robertphillips@google.come9cd27d2013-10-16 17:48:11 +0000330 for (int j = 0; j < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++j) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000331 if (0 == strcmp(FLAGS_config[i], gConfigs[j].name)) {
332 *configs.append() = j;
borenet@google.com4e061d32013-09-16 19:12:19 +0000333 } else if (0 == strcmp(FLAGS_config[i], kDefaultsConfigStr)) {
334 runDefaultConfigs = true;
mtklein@google.comc2897432013-09-10 19:23:38 +0000335 }
336 }
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +0000337 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000338 // If there weren't any, fill in with defaults.
borenet@google.com4e061d32013-09-16 19:12:19 +0000339 if (runDefaultConfigs) {
robertphillips@google.come9cd27d2013-10-16 17:48:11 +0000340 for (int i = 0; i < static_cast<int>(SK_ARRAY_COUNT(gConfigs)); ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000341 if (gConfigs[i].runByDefault) {
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000342 *configs.append() = i;
343 }
tomhudson@google.com13eaaaa2012-04-16 18:00:40 +0000344 }
345 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000346 // Filter out things we can't run.
347 if (kNormal_BenchMode != benchMode) {
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000348 // Non-rendering configs only run in normal mode
349 for (int i = 0; i < configs.count(); ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000350 const Config& config = gConfigs[configs[i]];
tfarinaf168b862014-06-19 12:32:29 -0700351 if (Benchmark::kNonRendering_Backend == config.backend) {
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000352 configs.remove(i, 1);
353 --i;
354 }
355 }
356 }
bsalomon69456182014-07-07 10:46:58 -0700357 // Apply the gpu/cpu only flags
358 for (int i = 0; i < configs.count(); ++i) {
359 const Config& config = gConfigs[configs[i]];
360 if (config.backend == Benchmark::kGPU_Backend) {
361 if (!FLAGS_gpu) {
362 configs.remove(i, 1);
363 --i;
364 }
365 } else if (!FLAGS_cpu) {
366 configs.remove(i, 1);
367 --i;
368 }
369 }
scroggo@google.com111fd112013-09-25 21:42:12 +0000370
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000371#if SK_SUPPORT_GPU
kkinnunen80549fc2014-06-30 06:36:31 -0700372 GrGLStandard gpuAPI = kNone_GrGLStandard;
373 if (1 == FLAGS_gpuAPI.count()) {
374 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
375 gpuAPI = kGL_GrGLStandard;
376 } else if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
377 gpuAPI = kGLES_GrGLStandard;
378 } else {
379 SkDebugf("Selected gpu API could not be used. Using the default.\n");
380 }
381 } else if (FLAGS_gpuAPI.count() > 1) {
382 SkDebugf("Selected gpu API could not be used. Using the default.\n");
383 }
384
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000385 for (int i = 0; i < configs.count(); ++i) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000386 const Config& config = gConfigs[configs[i]];
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000387
tfarinaf168b862014-06-19 12:32:29 -0700388 if (Benchmark::kGPU_Backend == config.backend) {
kkinnunen80549fc2014-06-30 06:36:31 -0700389 GrContext* context = gContextFactory.get(config.contextType, gpuAPI);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000390 if (NULL == context) {
commit-bot@chromium.org0f298cc2014-04-30 15:54:29 +0000391 SkDebugf("GrContext could not be created for config %s. Config will be skipped.\n",
392 config.name);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000393 configs.remove(i);
394 --i;
395 continue;
396 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000397 if (config.sampleCount > context->getMaxSampleCount()){
commit-bot@chromium.org0f298cc2014-04-30 15:54:29 +0000398 SkDebugf(
399 "Sample count (%d) for config %s is not supported. Config will be skipped.\n",
400 config.sampleCount, config.name);
bsalomon@google.com8a70eef2013-03-19 13:58:55 +0000401 configs.remove(i);
402 --i;
403 continue;
404 }
405 }
406 }
407#endif
408
mtklein@google.comc2897432013-09-10 19:23:38 +0000409 // All flags should be parsed now. Report our settings.
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000410 if (FLAGS_runOnce) {
411 logger.logError("bench was run with --runOnce, so we're going to hide the times."
412 " It's for your own good!\n");
mtklein@google.comc2897432013-09-10 19:23:38 +0000413 }
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000414 writer.option("mode", FLAGS_mode[0]);
415 writer.option("alpha", SkStringPrintf("0x%02X", alpha).c_str());
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000416 writer.option("dither", SkTriState::Name[dither]);
417
418 writer.option("rotate", SkStringPrintf("%d", FLAGS_rotate).c_str());
419 writer.option("scale", SkStringPrintf("%d", FLAGS_scale).c_str());
420 writer.option("clip", SkStringPrintf("%d", FLAGS_clip).c_str());
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000421
bungeman@google.coma5d48412011-06-15 17:25:46 +0000422#if defined(SK_BUILD_FOR_WIN32)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000423 writer.option("system", "WIN32");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000424#elif defined(SK_BUILD_FOR_MAC)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000425 writer.option("system", "MAC");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000426#elif defined(SK_BUILD_FOR_ANDROID)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000427 writer.option("system", "ANDROID");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000428#elif defined(SK_BUILD_FOR_UNIX)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000429 writer.option("system", "UNIX");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000430#else
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000431 writer.option("system", "other");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000432#endif
433
434#if defined(SK_DEBUG)
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000435 writer.option("build", "DEBUG");
436#else
437 writer.option("build", "RELEASE");
bungeman@google.coma5d48412011-06-15 17:25:46 +0000438#endif
mtklein@google.comc2897432013-09-10 19:23:38 +0000439
440 // Set texture cache limits if non-default.
bsalomon@google.com5c90e292013-02-22 19:17:13 +0000441 for (size_t i = 0; i < SK_ARRAY_COUNT(gConfigs); ++i) {
bsalomon@google.comcb265352013-02-22 16:13:16 +0000442#if SK_SUPPORT_GPU
mtklein@google.comc2897432013-09-10 19:23:38 +0000443 const Config& config = gConfigs[i];
tfarinaf168b862014-06-19 12:32:29 -0700444 if (Benchmark::kGPU_Backend != config.backend) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000445 continue;
bsalomon@google.comcb265352013-02-22 16:13:16 +0000446 }
kkinnunen80549fc2014-06-30 06:36:31 -0700447 GrContext* context = gContextFactory.get(config.contextType, gpuAPI);
mtklein@google.comc2897432013-09-10 19:23:38 +0000448 if (NULL == context) {
449 continue;
450 }
451
452 size_t bytes;
453 int count;
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000454 context->getResourceCacheLimits(&count, &bytes);
mtklein@google.comc2897432013-09-10 19:23:38 +0000455 if (-1 != FLAGS_gpuCacheBytes) {
456 bytes = static_cast<size_t>(FLAGS_gpuCacheBytes);
457 }
458 if (-1 != FLAGS_gpuCacheCount) {
459 count = FLAGS_gpuCacheCount;
460 }
commit-bot@chromium.org95c20032014-05-09 14:29:32 +0000461 context->setResourceCacheLimits(count, bytes);
bsalomon@google.comcb265352013-02-22 16:13:16 +0000462#endif
463 }
bsalomon@google.com74913722011-10-27 20:44:19 +0000464
mtklein@google.comc2897432013-09-10 19:23:38 +0000465 // Run each bench in each configuration it supports and we asked for.
466 Iter iter;
tfarinaf168b862014-06-19 12:32:29 -0700467 Benchmark* bench;
reed@android.combd700c32009-01-05 03:34:50 +0000468 while ((bench = iter.next()) != NULL) {
tfarinaf168b862014-06-19 12:32:29 -0700469 SkAutoTUnref<Benchmark> benchUnref(bench);
mtklein@google.comc2897432013-09-10 19:23:38 +0000470 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getName())) {
reed@android.comb398fe82009-01-07 11:47:57 +0000471 continue;
472 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000473
mtklein@google.comc2897432013-09-10 19:23:38 +0000474 bench->setForceAlpha(alpha);
mtklein@google.comc2897432013-09-10 19:23:38 +0000475 bench->setDither(dither);
mtklein683e9062014-06-18 07:15:48 -0700476 bench->preDraw();
bsalomon@google.com30e6d2c2012-08-13 14:03:31 +0000477
mtklein@google.comc2897432013-09-10 19:23:38 +0000478 bool loggedBenchName = false;
479 for (int i = 0; i < configs.count(); ++i) {
480 const int configIndex = configs[i];
481 const Config& config = gConfigs[configIndex];
tomhudson@google.com13eaaaa2012-04-16 18:00:40 +0000482
commit-bot@chromium.org644629c2013-11-21 06:21:58 +0000483 if (!bench->isSuitableFor(config.backend)) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000484 continue;
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000485 }
486
bsalomon@google.comcb265352013-02-22 16:13:16 +0000487 GrContext* context = NULL;
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000488#if SK_SUPPORT_GPU
sugoi@google.com9c55f802013-03-07 20:52:59 +0000489 SkGLContextHelper* glContext = NULL;
tfarinaf168b862014-06-19 12:32:29 -0700490 if (Benchmark::kGPU_Backend == config.backend) {
kkinnunen80549fc2014-06-30 06:36:31 -0700491 context = gContextFactory.get(config.contextType, gpuAPI);
bsalomon@google.comcb265352013-02-22 16:13:16 +0000492 if (NULL == context) {
493 continue;
494 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000495 glContext = gContextFactory.getGLContext(config.contextType);
mike@reedtribe.orga9015f82011-05-17 02:25:05 +0000496 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000497#endif
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000498
mtklein@google.comc2897432013-09-10 19:23:38 +0000499 SkAutoTUnref<SkCanvas> canvas;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000500 SkAutoTUnref<SkPicture> recordFrom;
501 SkPictureRecorder recorderTo;
mtklein@google.comc2897432013-09-10 19:23:38 +0000502 const SkIPoint dim = bench->getSize();
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000503
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000504 SkAutoTUnref<SkSurface> surface;
tfarinaf168b862014-06-19 12:32:29 -0700505 if (Benchmark::kNonRendering_Backend != config.backend) {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000506 surface.reset(make_surface(config.fColorType,
507 dim,
508 config.backend,
509 config.sampleCount,
510 context));
511 if (!surface.get()) {
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000512 logger.logError(SkStringPrintf(
513 "Device creation failure for config %s. Will skip.\n", config.name));
mtklein@google.comc2897432013-09-10 19:23:38 +0000514 continue;
keyar@chromium.orgfdd909c2012-07-20 23:03:42 +0000515 }
junov@chromium.orgfb103892012-09-20 19:35:43 +0000516
mtklein@google.comc2897432013-09-10 19:23:38 +0000517 switch(benchMode) {
518 case kDeferredSilent_BenchMode:
519 case kDeferred_BenchMode:
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000520 canvas.reset(SkDeferredCanvas::Create(surface.get()));
mtklein@google.comc2897432013-09-10 19:23:38 +0000521 break;
522 case kRecord_BenchMode:
robertphillips9f1c2412014-06-09 06:25:34 -0700523 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY)));
mtklein@google.comc2897432013-09-10 19:23:38 +0000524 break;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000525 case kPictureRecord_BenchMode: {
526 SkPictureRecorder recorderFrom;
robertphillips9f1c2412014-06-09 06:25:34 -0700527 bench->draw(1, recorderFrom.beginRecording(dim.fX, dim.fY));
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000528 recordFrom.reset(recorderFrom.endRecording());
robertphillips9f1c2412014-06-09 06:25:34 -0700529 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY)));
mtklein@google.comc2897432013-09-10 19:23:38 +0000530 break;
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000531 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000532 case kNormal_BenchMode:
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000533 canvas.reset(SkRef(surface->getCanvas()));
mtklein@google.comc2897432013-09-10 19:23:38 +0000534 break;
535 default:
536 SkASSERT(false);
537 }
538 }
539
540 if (NULL != canvas) {
541 canvas->clear(SK_ColorWHITE);
skia.committer@gmail.com51997012014-04-14 03:04:57 +0000542 if (FLAGS_clip) {
543 perform_clip(canvas, dim.fX, dim.fY);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000544 }
skia.committer@gmail.com51997012014-04-14 03:04:57 +0000545 if (FLAGS_scale) {
546 perform_scale(canvas, dim.fX, dim.fY);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000547 }
skia.committer@gmail.com51997012014-04-14 03:04:57 +0000548 if (FLAGS_rotate) {
549 perform_rotate(canvas, dim.fX, dim.fY);
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000550 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000551 }
552
553 if (!loggedBenchName) {
554 loggedBenchName = true;
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000555 writer.bench(bench->getName(), dim.fX, dim.fY);
mtklein@google.comc2897432013-09-10 19:23:38 +0000556 }
557
558#if SK_SUPPORT_GPU
559 SkGLContextHelper* contextHelper = NULL;
tfarinaf168b862014-06-19 12:32:29 -0700560 if (Benchmark::kGPU_Backend == config.backend) {
mtklein@google.comc2897432013-09-10 19:23:38 +0000561 contextHelper = gContextFactory.getGLContext(config.contextType);
562 }
mtklein9ac68ee2014-06-20 11:29:20 -0700563 Timer timer(contextHelper);
mtklein@google.comc2897432013-09-10 19:23:38 +0000564#else
mtklein9ac68ee2014-06-20 11:29:20 -0700565 Timer timer;
mtklein@google.comc2897432013-09-10 19:23:38 +0000566#endif
567
mtklein@google.com9ef1d212013-09-13 20:39:50 +0000568 double previous = std::numeric_limits<double>::infinity();
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000569 bool converged = false;
djsollen@google.com70de4da2013-10-10 17:33:39 +0000570
571 // variables used to compute loopsPerFrame
572 double frameIntervalTime = 0.0f;
573 int frameIntervalTotalLoops = 0;
574
575 bool frameIntervalComputed = false;
576 int loopsPerFrame = 0;
577 int loopsPerIter = 0;
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000578 if (FLAGS_verbose) { SkDebugf("%s %s: ", bench->getName(), config.name); }
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000579 if (!FLAGS_dryRun) {
580 do {
581 // Ramp up 1 -> 2 -> 4 -> 8 -> 16 -> ... -> ~1 billion.
582 loopsPerIter = (loopsPerIter == 0) ? 1 : loopsPerIter * 2;
583 if (loopsPerIter >= (1<<30) || timer.fWall > FLAGS_maxMs) {
584 // If you find it takes more than a billion loops to get up to 20ms of runtime,
585 // you've got a computer clocked at several THz or have a broken benchmark. ;)
586 // "1B ought to be enough for anybody."
587 logger.logError(SkStringPrintf(
588 "\nCan't get %s %s to converge in %dms (%d loops)",
589 bench->getName(), config.name, FLAGS_maxMs, loopsPerIter));
590 break;
djsollen@google.com70de4da2013-10-10 17:33:39 +0000591 }
592
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000593 if ((benchMode == kRecord_BenchMode || benchMode == kPictureRecord_BenchMode)) {
594 // Clear the recorded commands so that they do not accumulate.
robertphillips9f1c2412014-06-09 06:25:34 -0700595 canvas.reset(SkRef(recorderTo.beginRecording(dim.fX, dim.fY)));
djsollen@google.com70de4da2013-10-10 17:33:39 +0000596 }
597
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000598 timer.start();
599 // Inner loop that allows us to break the run into smaller
600 // chunks (e.g. frames). This is especially useful for the GPU
601 // as we can flush and/or swap buffers to keep the GPU from
602 // queuing up too much work.
603 for (int loopCount = loopsPerIter; loopCount > 0; ) {
604 // Save and restore around each call to draw() to guarantee a pristine canvas.
605 SkAutoCanvasRestore saveRestore(canvas, true/*also save*/);
djsollen@google.com70de4da2013-10-10 17:33:39 +0000606
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000607 int loops;
608 if (frameIntervalComputed && loopCount > loopsPerFrame) {
609 loops = loopsPerFrame;
610 loopCount -= loopsPerFrame;
611 } else {
612 loops = loopCount;
613 loopCount = 0;
djsollen@google.com70de4da2013-10-10 17:33:39 +0000614 }
djsollen@google.comdcfed6c2013-10-10 18:48:27 +0000615
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000616 if (benchMode == kPictureRecord_BenchMode) {
robertphillips@google.com84b18c72014-04-13 19:09:42 +0000617 recordFrom->draw(canvas);
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000618 } else {
619 bench->draw(loops, canvas);
620 }
621
622 if (kDeferredSilent_BenchMode == benchMode) {
623 static_cast<SkDeferredCanvas*>(canvas.get())->silentFlush();
624 } else if (NULL != canvas) {
625 canvas->flush();
626 }
627
628 #if SK_SUPPORT_GPU
629 // swap drawing buffers on each frame to prevent the GPU
630 // from queuing up too much work
631 if (NULL != glContext) {
632 glContext->swapBuffers();
633 }
634 #endif
635 }
636
637
638
639 // Stop truncated timers before GL calls complete, and stop the full timers after.
640 timer.truncatedEnd();
641 #if SK_SUPPORT_GPU
642 if (NULL != glContext) {
643 context->flush();
644 SK_GL(*glContext, Finish());
645 }
646 #endif
647 timer.end();
648
649 // setup the frame interval for subsequent iterations
650 if (!frameIntervalComputed) {
651 frameIntervalTime += timer.fWall;
652 frameIntervalTotalLoops += loopsPerIter;
653 if (frameIntervalTime >= FLAGS_minMs) {
654 frameIntervalComputed = true;
655 loopsPerFrame =
656 (int)(((double)frameIntervalTotalLoops / frameIntervalTime) * FLAGS_minMs);
657 if (loopsPerFrame < 1) {
658 loopsPerFrame = 1;
659 }
660 // SkDebugf(" %s has %d loops in %f ms (normalized to %d)\n",
661 // bench->getName(), frameIntervalTotalLoops,
662 // timer.fWall, loopsPerFrame);
663 }
664 }
665
666 const double current = timer.fWall / loopsPerIter;
667 if (FLAGS_verbose && current > previous) { SkDebugf("↑"); }
668 if (FLAGS_verbose) { SkDebugf("%.3g ", current); }
669 converged = HasConverged(previous, current, timer.fWall);
670 previous = current;
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000671 } while (!FLAGS_runOnce && !converged);
commit-bot@chromium.org56b7a6d2014-03-13 16:22:00 +0000672 }
mtklein@google.comdbd41c82013-09-13 20:11:09 +0000673 if (FLAGS_verbose) { SkDebugf("\n"); }
mtklein@google.comc2897432013-09-10 19:23:38 +0000674
tfarinaf168b862014-06-19 12:32:29 -0700675 if (!FLAGS_dryRun && FLAGS_outDir.count() && Benchmark::kNonRendering_Backend != config.backend) {
reed@google.com1bc6c6a2014-02-04 14:02:44 +0000676 SkAutoTUnref<SkImage> image(surface->newImageSnapshot());
677 if (image.get()) {
678 saveFile(bench->getName(), config.name, FLAGS_outDir[0],
679 image);
680 }
mtklein@google.comc2897432013-09-10 19:23:38 +0000681 }
682
commit-bot@chromium.org4bbe2e52014-04-21 21:12:32 +0000683 if (FLAGS_runOnce) {
684 // Let's not mislead ourselves by looking at Debug build or single iteration bench times!
mtklein@google.comc2897432013-09-10 19:23:38 +0000685 continue;
686 }
687
688 // Normalize to ms per 1000 iterations.
djsollen@google.com70de4da2013-10-10 17:33:39 +0000689 const double normalize = 1000.0 / loopsPerIter;
mtklein@google.comc2897432013-09-10 19:23:38 +0000690 const struct { char shortName; const char* longName; double ms; } times[] = {
691 {'w', "msecs", normalize * timer.fWall},
692 {'W', "Wmsecs", normalize * timer.fTruncatedWall},
693 {'c', "cmsecs", normalize * timer.fCpu},
694 {'C', "Cmsecs", normalize * timer.fTruncatedCpu},
695 {'g', "gmsecs", normalize * timer.fGpu},
696 };
697
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000698 writer.config(config.name);
mtklein@google.comc2897432013-09-10 19:23:38 +0000699 for (size_t i = 0; i < SK_ARRAY_COUNT(times); i++) {
700 if (strchr(FLAGS_timers[0], times[i].shortName) && times[i].ms > 0) {
commit-bot@chromium.orge3bb3bc2013-12-03 18:16:48 +0000701 writer.timer(times[i].longName, times[i].ms);
commit-bot@chromium.org7495f592013-06-03 19:31:07 +0000702 }
reed@google.com25df8882011-07-14 19:03:58 +0000703 }
bsalomon@google.com604a56a2013-03-15 15:42:15 +0000704 }
reed@android.combd700c32009-01-05 03:34:50 +0000705 }
bsalomon@google.comcf8fb1f2012-08-02 14:03:32 +0000706#if SK_SUPPORT_GPU
bsalomon@google.comcb265352013-02-22 16:13:16 +0000707 gContextFactory.destroyContexts();
robertphillips@google.com9d594202012-09-13 14:05:00 +0000708#endif
reed@android.combd700c32009-01-05 03:34:50 +0000709 return 0;
710}
caryclark@google.com5987f582012-10-02 18:33:14 +0000711
borenet@google.com7158e6a2012-11-01 17:43:44 +0000712#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
caryclark@google.com5987f582012-10-02 18:33:14 +0000713int main(int argc, char * const argv[]) {
714 return tool_main(argc, (char**) argv);
715}
716#endif