mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 8 | #include <ctype.h> |
| 9 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 10 | #include "nanobench.h" |
| 11 | |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 12 | #include "AndroidCodecBench.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 13 | #include "Benchmark.h" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 14 | #include "BitmapRegionDecoderBench.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 15 | #include "CodecBench.h" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 16 | #include "CodecBenchPriv.h" |
msarett | 2cee902 | 2016-06-03 08:25:21 -0700 | [diff] [blame] | 17 | #include "ColorCodecBench.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 18 | #include "CrashHandler.h" |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 19 | #include "GMBench.h" |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 20 | #include "ProcStats.h" |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 21 | #include "ResultsWriter.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 22 | #include "RecordingBench.h" |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 23 | #include "SKPAnimationBench.h" |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 24 | #include "SKPBench.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 25 | #include "Stats.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 26 | |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 27 | #include "SkAndroidCodec.h" |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 28 | #include "SkBitmapRegionDecoder.h" |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 29 | #include "SkBBoxHierarchy.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 30 | #include "SkCanvas.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 31 | #include "SkCodec.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 32 | #include "SkCommonFlags.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 33 | #include "SkCommonFlagsConfig.h" |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 34 | #include "SkData.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 35 | #include "SkForceLinking.h" |
| 36 | #include "SkGraphics.h" |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 37 | #include "SkLeanWindows.h" |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 38 | #include "SkOSFile.h" |
| 39 | #include "SkPictureRecorder.h" |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 40 | #include "SkPictureUtils.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 41 | #include "SkString.h" |
| 42 | #include "SkSurface.h" |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 43 | #include "SkSVGDOM.h" |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 44 | #include "SkTaskGroup.h" |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 45 | #include "SkThreadUtils.h" |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 46 | #include "ThermalManager.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 47 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 48 | #include <stdlib.h> |
| 49 | |
scroggo | 38ce0a7 | 2016-01-07 07:28:47 -0800 | [diff] [blame] | 50 | #ifndef SK_BUILD_FOR_WIN32 |
| 51 | #include <unistd.h> |
| 52 | #endif |
| 53 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 54 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 55 | #include "nanobenchAndroid.h" |
| 56 | #endif |
| 57 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 58 | #if SK_SUPPORT_GPU |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 59 | #include "gl/GrGLDefines.h" |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 60 | #include "GrCaps.h" |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 61 | #include "GrContextFactory.h" |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 62 | #include "gl/GrGLUtil.h" |
| 63 | using sk_gpu_test::GrContextFactory; |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 64 | using sk_gpu_test::TestContext; |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 65 | SkAutoTDelete<GrContextFactory> gGrFactory; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 66 | #endif |
| 67 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 68 | struct GrContextOptions; |
| 69 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 70 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 71 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 72 | static const int kAutoTuneLoops = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 73 | |
mtklein | b511042 | 2014-08-07 15:20:02 -0700 | [diff] [blame] | 74 | static const int kDefaultLoops = |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 75 | #ifdef SK_DEBUG |
| 76 | 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 77 | #else |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 78 | kAutoTuneLoops; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 79 | #endif |
| 80 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 81 | static SkString loops_help_txt() { |
| 82 | SkString help; |
| 83 | help.printf("Number of times to run each bench. Set this to %d to auto-" |
| 84 | "tune for each bench. Timings are only reported when auto-tuning.", |
| 85 | kAutoTuneLoops); |
| 86 | return help; |
| 87 | } |
| 88 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 89 | static SkString to_string(int n) { |
| 90 | SkString str; |
| 91 | str.appendS32(n); |
| 92 | return str; |
| 93 | } |
| 94 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 95 | DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str()); |
| 96 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 97 | DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 98 | DEFINE_int32(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 99 | DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); |
| 100 | DEFINE_double(overheadGoal, 0.0001, |
| 101 | "Loop until timer overhead is at most this fraction of our measurments."); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 102 | DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 103 | DEFINE_int32(gpuFrameLag, 5, "If unknown, estimated maximum number of frames GPU allows to lag."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 104 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 105 | DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 106 | DEFINE_int32(maxCalibrationAttempts, 3, |
| 107 | "Try up to this many times to guess loops for a bench, or skip the bench."); |
| 108 | DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 109 | DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 110 | DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 111 | DEFINE_string(zoom, "1.0,0", "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom " |
| 112 | "function that ping-pongs between 1.0 and zoomMax."); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 113 | DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 114 | DEFINE_bool(lite, false, "Use SkLiteRecorder in recording benchmarks?"); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 115 | DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 116 | DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?"); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 117 | DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 118 | DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 119 | DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 120 | DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json"); |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 121 | DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out"); |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 122 | DEFINE_string(useThermalManager, "0,1,10,1000", "enabled,threshold,sleepTimeMs,TimeoutMs for " |
| 123 | "thermalManager\n"); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 124 | |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 125 | DEFINE_string(sourceType, "", |
| 126 | "Apply usual --match rules to source type: bench, gm, skp, image, etc."); |
| 127 | DEFINE_string(benchType, "", |
| 128 | "Apply usual --match rules to bench type: micro, recording, playback, skcodec, etc."); |
| 129 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 130 | static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
| 131 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 132 | static SkString humanize(double ms) { |
mtklein | dc5bbab | 2014-09-24 06:34:09 -0700 | [diff] [blame] | 133 | if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 134 | return HumanizeMs(ms); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 135 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 136 | #define HUMANIZE(ms) humanize(ms).c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 137 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 138 | bool Target::init(SkImageInfo info, Benchmark* bench) { |
| 139 | if (Benchmark::kRaster_Backend == config.backend) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 140 | this->surface = SkSurface::MakeRaster(info); |
| 141 | if (!this->surface) { |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 142 | return false; |
| 143 | } |
| 144 | } |
| 145 | return true; |
| 146 | } |
| 147 | bool Target::capturePixels(SkBitmap* bmp) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 148 | SkCanvas* canvas = this->getCanvas(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 149 | if (!canvas) { |
| 150 | return false; |
| 151 | } |
| 152 | bmp->setInfo(canvas->imageInfo()); |
| 153 | if (!canvas->readPixels(bmp, 0, 0)) { |
| 154 | SkDebugf("Can't read canvas pixels.\n"); |
| 155 | return false; |
| 156 | } |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | #if SK_SUPPORT_GPU |
| 161 | struct GPUTarget : public Target { |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 162 | explicit GPUTarget(const Config& c) : Target(c), context(nullptr) { } |
| 163 | TestContext* context; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 164 | |
| 165 | void setup() override { |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 166 | this->context->makeCurrent(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 167 | // Make sure we're done with whatever came before. |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 168 | this->context->finish(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 169 | } |
| 170 | void endTiming() override { |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 171 | if (this->context) { |
| 172 | this->context->waitOnSyncOrSwap(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | void fence() override { |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 176 | this->context->finish(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 177 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 178 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 179 | bool needsFrameTiming(int* maxFrameLag) const override { |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 180 | if (!this->context->getMaxGpuFrameLag(maxFrameLag)) { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 181 | // Frame lag is unknown. |
| 182 | *maxFrameLag = FLAGS_gpuFrameLag; |
| 183 | } |
| 184 | return true; |
| 185 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 186 | bool init(SkImageInfo info, Benchmark* bench) override { |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 187 | uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : |
| 188 | 0; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 189 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 190 | this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config.ctxType, |
| 191 | this->config.ctxOptions), |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 192 | SkBudgeted::kNo, info, |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 193 | this->config.samples, &props); |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 194 | this->context = gGrFactory->getContextInfo(this->config.ctxType, |
| 195 | this->config.ctxOptions).testContext(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 196 | if (!this->surface.get()) { |
| 197 | return false; |
| 198 | } |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 199 | if (!this->context->fenceSyncSupport()) { |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 200 | SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. " |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 201 | "Timings might not be accurate.\n", this->config.name.c_str()); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 202 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 203 | return true; |
| 204 | } |
| 205 | void fillOptions(ResultsWriter* log) override { |
| 206 | const GrGLubyte* version; |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 207 | if (this->context->backend() == kOpenGL_GrBackend) { |
| 208 | const GrGLInterface* gl = |
| 209 | reinterpret_cast<const GrGLInterface*>(this->context->backendContext()); |
| 210 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION)); |
| 211 | log->configOption("GL_VERSION", (const char*)(version)); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 212 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 213 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_RENDERER)); |
| 214 | log->configOption("GL_RENDERER", (const char*) version); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 215 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 216 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_VENDOR)); |
| 217 | log->configOption("GL_VENDOR", (const char*) version); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 218 | |
bsalomon | c869932 | 2016-05-11 11:55:36 -0700 | [diff] [blame] | 219 | GR_GL_CALL_RET(gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 220 | log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 221 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 222 | } |
| 223 | }; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 224 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 225 | #endif |
| 226 | |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 227 | static double time(int loops, Benchmark* bench, Target* target) { |
| 228 | SkCanvas* canvas = target->getCanvas(); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 229 | if (canvas) { |
| 230 | canvas->clear(SK_ColorWHITE); |
| 231 | } |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 232 | bench->preDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 233 | double start = now_ms(); |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 234 | canvas = target->beginTiming(canvas); |
| 235 | bench->draw(loops, canvas); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 236 | if (canvas) { |
| 237 | canvas->flush(); |
| 238 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 239 | target->endTiming(); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 240 | double elapsed = now_ms() - start; |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 241 | bench->postDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 242 | return elapsed; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 243 | } |
| 244 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 245 | static double estimate_timer_overhead() { |
| 246 | double overhead = 0; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 247 | for (int i = 0; i < FLAGS_overheadLoops; i++) { |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 248 | double start = now_ms(); |
| 249 | overhead += now_ms() - start; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 250 | } |
| 251 | return overhead / FLAGS_overheadLoops; |
| 252 | } |
| 253 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 254 | static int detect_forever_loops(int loops) { |
| 255 | // look for a magic run-forever value |
| 256 | if (loops < 0) { |
| 257 | loops = SK_MaxS32; |
| 258 | } |
| 259 | return loops; |
| 260 | } |
| 261 | |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 262 | static int clamp_loops(int loops) { |
| 263 | if (loops < 1) { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 264 | SkDebugf("ERROR: clamping loops from %d to 1. " |
| 265 | "There's probably something wrong with the bench.\n", loops); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 266 | return 1; |
| 267 | } |
| 268 | if (loops > FLAGS_maxLoops) { |
| 269 | SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops); |
| 270 | return FLAGS_maxLoops; |
| 271 | } |
| 272 | return loops; |
| 273 | } |
| 274 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 275 | static bool write_canvas_png(Target* target, const SkString& filename) { |
| 276 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 277 | if (filename.isEmpty()) { |
| 278 | return false; |
| 279 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 280 | if (target->getCanvas() && |
| 281 | kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 282 | return false; |
| 283 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 284 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 285 | SkBitmap bmp; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 286 | |
| 287 | if (!target->capturePixels(&bmp)) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 288 | return false; |
| 289 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 290 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 291 | SkString dir = SkOSPath::Dirname(filename.c_str()); |
| 292 | if (!sk_mkdir(dir.c_str())) { |
| 293 | SkDebugf("Can't make dir %s.\n", dir.c_str()); |
| 294 | return false; |
| 295 | } |
| 296 | SkFILEWStream stream(filename.c_str()); |
| 297 | if (!stream.isValid()) { |
| 298 | SkDebugf("Can't write %s.\n", filename.c_str()); |
| 299 | return false; |
| 300 | } |
| 301 | if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) { |
| 302 | SkDebugf("Can't encode a PNG.\n"); |
| 303 | return false; |
| 304 | } |
| 305 | return true; |
| 306 | } |
| 307 | |
| 308 | static int kFailedLoops = -2; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 309 | static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 310 | // First figure out approximately how many loops of bench it takes to make overhead negligible. |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 311 | double bench_plus_overhead = 0.0; |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 312 | int round = 0; |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 313 | int loops = bench->calculateLoops(FLAGS_loops); |
| 314 | if (kAutoTuneLoops == loops) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 315 | while (bench_plus_overhead < overhead) { |
| 316 | if (round++ == FLAGS_maxCalibrationAttempts) { |
| 317 | SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 318 | bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead)); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 319 | return kFailedLoops; |
| 320 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 321 | bench_plus_overhead = time(1, bench, target); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 322 | } |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 323 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 324 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 325 | // Later we'll just start and stop the timer once but loop N times. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 326 | // We'll pick N to make timer overhead negligible: |
| 327 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 328 | // overhead |
| 329 | // ------------------------- < FLAGS_overheadGoal |
| 330 | // overhead + N * Bench Time |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 331 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 332 | // where bench_plus_overhead ≈ overhead + Bench Time. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 333 | // |
| 334 | // Doing some math, we get: |
| 335 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 336 | // (overhead / FLAGS_overheadGoal) - overhead |
| 337 | // ------------------------------------------ < N |
| 338 | // bench_plus_overhead - overhead) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 339 | // |
| 340 | // Luckily, this also works well in practice. :) |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 341 | if (kAutoTuneLoops == loops) { |
| 342 | const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 343 | const double denom = bench_plus_overhead - overhead; |
| 344 | loops = (int)ceil(numer / denom); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 345 | loops = clamp_loops(loops); |
| 346 | } else { |
| 347 | loops = detect_forever_loops(loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 348 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 349 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 350 | return loops; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 351 | } |
| 352 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 353 | static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 354 | // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs. |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 355 | int loops = bench->calculateLoops(FLAGS_loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 356 | if (kAutoTuneLoops == loops) { |
| 357 | loops = 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 358 | double elapsed = 0; |
| 359 | do { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 360 | if (1<<30 == loops) { |
| 361 | // We're about to wrap. Something's wrong with the bench. |
| 362 | loops = 0; |
| 363 | break; |
| 364 | } |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 365 | loops *= 2; |
| 366 | // If the GPU lets frames lag at all, we need to make sure we're timing |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 367 | // _this_ round, not still timing last round. |
| 368 | for (int i = 0; i < maxGpuFrameLag; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 369 | elapsed = time(loops, bench, target); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 370 | } |
| 371 | } while (elapsed < FLAGS_gpuMs); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 372 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 373 | // We've overshot at least a little. Scale back linearly. |
| 374 | loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 375 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 376 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 377 | // Make sure we're not still timing our calibration. |
| 378 | target->fence(); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 379 | } else { |
| 380 | loops = detect_forever_loops(loops); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 381 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 382 | |
| 383 | // Pretty much the same deal as the calibration: do some warmup to make |
| 384 | // sure we're timing steady-state pipelined frames. |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 385 | for (int i = 0; i < maxGpuFrameLag - 1; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 386 | time(loops, bench, target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 387 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 388 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 389 | return loops; |
| 390 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 391 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 392 | #if SK_SUPPORT_GPU |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 393 | #define kBogusContextType GrContextFactory::kNativeGL_ContextType |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 394 | #define kBogusContextOptions GrContextFactory::ContextOptions::kNone |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 395 | #else |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 396 | #define kBogusContextType 0 |
| 397 | #define kBogusContextOptions 0 |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 398 | #endif |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 399 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 400 | static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* configs) { |
| 401 | |
| 402 | #if SK_SUPPORT_GPU |
| 403 | if (const auto* gpuConfig = config->asConfigGpu()) { |
| 404 | if (!FLAGS_gpu) |
| 405 | return; |
| 406 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 407 | const auto ctxType = gpuConfig->getContextType(); |
csmartdalton | 6270e55 | 2016-09-13 10:41:49 -0700 | [diff] [blame] | 408 | const auto ctxOptions = gpuConfig->getContextOptions(); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 409 | const auto sampleCount = gpuConfig->getSamples(); |
| 410 | |
| 411 | if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) { |
| 412 | const auto maxSampleCount = ctx->caps()->maxSampleCount(); |
| 413 | if (sampleCount > ctx->caps()->maxSampleCount()) { |
| 414 | SkDebugf("Configuration sample count %d exceeds maximum %d.\n", |
| 415 | sampleCount, maxSampleCount); |
| 416 | return; |
| 417 | } |
| 418 | } else { |
| 419 | SkDebugf("No context was available matching config type and options.\n"); |
| 420 | return; |
| 421 | } |
| 422 | |
| 423 | Config target = { |
kkinnunen | d4e1c35 | 2016-03-01 23:41:26 -0800 | [diff] [blame] | 424 | gpuConfig->getTag(), |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 425 | Benchmark::kGPU_Backend, |
brianosman | 1a48e13 | 2016-06-20 09:41:41 -0700 | [diff] [blame] | 426 | gpuConfig->getColorType(), |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 427 | kPremul_SkAlphaType, |
brianosman | 1a48e13 | 2016-06-20 09:41:41 -0700 | [diff] [blame] | 428 | sk_ref_sp(gpuConfig->getColorSpace()), |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 429 | sampleCount, |
| 430 | ctxType, |
kkinnunen | d4e1c35 | 2016-03-01 23:41:26 -0800 | [diff] [blame] | 431 | ctxOptions, |
| 432 | gpuConfig->getUseDIText() |
| 433 | }; |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 434 | |
| 435 | configs->push_back(target); |
| 436 | return; |
| 437 | } |
| 438 | #endif |
| 439 | |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 440 | #define CPU_CONFIG(name, backend, color, alpha, colorSpace) \ |
| 441 | if (config->getTag().equals(#name)) { \ |
| 442 | Config config = { \ |
| 443 | SkString(#name), Benchmark::backend, color, alpha, colorSpace, \ |
| 444 | 0, kBogusContextType, kBogusContextOptions, false \ |
| 445 | }; \ |
| 446 | configs->push_back(config); \ |
| 447 | return; \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 448 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 449 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 450 | if (FLAGS_cpu) { |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 451 | CPU_CONFIG(nonrendering, kNonRendering_Backend, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 452 | kUnknown_SkColorType, kUnpremul_SkAlphaType, nullptr) |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 453 | |
| 454 | CPU_CONFIG(8888, kRaster_Backend, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 455 | kN32_SkColorType, kPremul_SkAlphaType, nullptr) |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 456 | CPU_CONFIG(565, kRaster_Backend, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 457 | kRGB_565_SkColorType, kOpaque_SkAlphaType, nullptr) |
| 458 | auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 459 | CPU_CONFIG(srgb, kRaster_Backend, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 460 | kN32_SkColorType, kPremul_SkAlphaType, srgbColorSpace) |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 461 | CPU_CONFIG(f16, kRaster_Backend, |
brianosman | 0e22eb8 | 2016-08-30 07:07:59 -0700 | [diff] [blame] | 462 | kRGBA_F16_SkColorType, kPremul_SkAlphaType, srgbColorSpace->makeLinearGamma()) |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 463 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 464 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 465 | #undef CPU_CONFIG |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 466 | |
| 467 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
djsollen | 817c72a | 2016-01-28 13:57:02 -0800 | [diff] [blame] | 468 | if (config->getTag().equals("hwui")) { |
mtklein | bb6c41b | 2016-03-08 11:31:11 -0800 | [diff] [blame] | 469 | Config config = { SkString("hwui"), Benchmark::kHWUI_Backend, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 470 | kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr, |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 471 | 0, kBogusContextType, kBogusContextOptions, false }; |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 472 | configs->push_back(config); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 473 | } |
| 474 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 475 | } |
| 476 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 477 | // Append all configs that are enabled and supported. |
| 478 | void create_configs(SkTArray<Config>* configs) { |
| 479 | SkCommandLineConfigArray array; |
| 480 | ParseConfigs(FLAGS_config, &array); |
| 481 | for (int i = 0; i < array.count(); ++i) { |
| 482 | create_config(array[i], configs); |
| 483 | } |
| 484 | } |
| 485 | |
brianosman | 9f1f6e2 | 2016-09-15 08:33:02 -0700 | [diff] [blame^] | 486 | // disable warning : switch statement contains default but no 'case' labels |
| 487 | #if defined _WIN32 |
| 488 | #pragma warning ( push ) |
| 489 | #pragma warning ( disable : 4065 ) |
| 490 | #endif |
| 491 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 492 | // If bench is enabled for config, returns a Target* for it, otherwise nullptr. |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 493 | static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 494 | if (!bench->isSuitableFor(config.backend)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 495 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 496 | } |
| 497 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 498 | SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 499 | config.color, config.alpha, config.colorSpace); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 500 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 501 | Target* target = nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 502 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 503 | switch (config.backend) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 504 | #if SK_SUPPORT_GPU |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 505 | case Benchmark::kGPU_Backend: |
| 506 | target = new GPUTarget(config); |
| 507 | break; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 508 | #endif |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 509 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 510 | case Benchmark::kHWUI_Backend: |
| 511 | target = new HWUITarget(config, bench); |
| 512 | break; |
| 513 | #endif |
| 514 | default: |
| 515 | target = new Target(config); |
| 516 | break; |
| 517 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 518 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 519 | if (!target->init(info, bench)) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 520 | delete target; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 521 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 522 | } |
| 523 | return target; |
| 524 | } |
| 525 | |
brianosman | 9f1f6e2 | 2016-09-15 08:33:02 -0700 | [diff] [blame^] | 526 | #if defined _WIN32 |
| 527 | #pragma warning ( pop ) |
| 528 | #endif |
| 529 | |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 530 | static bool valid_brd_bench(sk_sp<SkData> encoded, SkColorType colorType, uint32_t sampleSize, |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 531 | uint32_t minOutputSize, int* width, int* height) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 532 | SkAutoTDelete<SkBitmapRegionDecoder> brd( |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 533 | SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 534 | if (nullptr == brd.get()) { |
| 535 | // This is indicates that subset decoding is not supported for a particular image format. |
| 536 | return false; |
| 537 | } |
| 538 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 539 | if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize > |
| 540 | (uint32_t) brd->height()) { |
| 541 | // This indicates that the image is not large enough to decode a |
| 542 | // minOutputSize x minOutputSize subset at the given sampleSize. |
| 543 | return false; |
| 544 | } |
| 545 | |
| 546 | // Set the image width and height. The calling code will use this to choose subsets to decode. |
| 547 | *width = brd->width(); |
| 548 | *height = brd->height(); |
| 549 | return true; |
| 550 | } |
| 551 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 552 | static void cleanup_run(Target* target) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 553 | delete target; |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 554 | #if SK_SUPPORT_GPU |
| 555 | if (FLAGS_abandonGpuContext) { |
| 556 | gGrFactory->abandonContexts(); |
| 557 | } |
| 558 | if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
| 559 | gGrFactory->destroyContexts(); |
| 560 | } |
| 561 | #endif |
| 562 | } |
| 563 | |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 564 | static void collect_files(const SkCommandLineFlags::StringArray& paths, const char* ext, |
| 565 | SkTArray<SkString>* list) { |
| 566 | for (int i = 0; i < paths.count(); ++i) { |
| 567 | if (SkStrEndsWith(paths[i], ext)) { |
| 568 | list->push_back(SkString(paths[i])); |
| 569 | } else { |
| 570 | SkOSFile::Iter it(paths[i], ext); |
| 571 | SkString path; |
| 572 | while (it.next(&path)) { |
| 573 | list->push_back(SkOSPath::Join(paths[i], path.c_str())); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 579 | class BenchmarkStream { |
| 580 | public: |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 581 | BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 582 | , fGMs(skiagm::GMRegistry::Head()) |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 583 | , fCurrentRecording(0) |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 584 | , fCurrentScale(0) |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 585 | , fCurrentSKP(0) |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 586 | , fCurrentSVG(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 587 | , fCurrentUseMPD(0) |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 588 | , fCurrentCodec(0) |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 589 | , fCurrentAndroidCodec(0) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 590 | , fCurrentBRDImage(0) |
msarett | 2cee902 | 2016-06-03 08:25:21 -0700 | [diff] [blame] | 591 | , fCurrentColorImage(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 592 | , fCurrentColorType(0) |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 593 | , fCurrentAlphaType(0) |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 594 | , fCurrentSubsetType(0) |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 595 | , fCurrentSampleSize(0) |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 596 | , fCurrentAnimSKP(0) { |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 597 | collect_files(FLAGS_skps, ".skp", &fSKPs); |
| 598 | collect_files(FLAGS_svgs, ".svg", &fSVGs); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 599 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 600 | if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 601 | &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) { |
| 602 | SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]); |
| 603 | exit(1); |
| 604 | } |
| 605 | |
| 606 | for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 607 | if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 608 | SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]); |
| 609 | exit(1); |
| 610 | } |
| 611 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 612 | |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 613 | if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) { |
| 614 | SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 615 | exit(1); |
| 616 | } |
| 617 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 618 | if (FLAGS_mpd) { |
| 619 | fUseMPDs.push_back() = true; |
| 620 | } |
mtklein | c751ecb | 2015-06-15 08:56:38 -0700 | [diff] [blame] | 621 | fUseMPDs.push_back() = false; |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 622 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 623 | // Prepare the images for decoding |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 624 | if (!CollectImages(FLAGS_images, &fImages)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 625 | exit(1); |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 626 | } |
msarett | 2cee902 | 2016-06-03 08:25:21 -0700 | [diff] [blame] | 627 | if (!CollectImages(FLAGS_colorImages, &fColorImages)) { |
| 628 | exit(1); |
| 629 | } |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 630 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 631 | // Choose the candidate color types for image decoding |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 632 | fColorTypes.push_back(kN32_SkColorType); |
| 633 | if (!FLAGS_simpleCodec) { |
| 634 | fColorTypes.push_back(kRGB_565_SkColorType); |
| 635 | fColorTypes.push_back(kAlpha_8_SkColorType); |
| 636 | fColorTypes.push_back(kIndex_8_SkColorType); |
| 637 | fColorTypes.push_back(kGray_8_SkColorType); |
| 638 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 639 | } |
| 640 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 641 | static sk_sp<SkPicture> ReadPicture(const char* path) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 642 | // Not strictly necessary, as it will be checked again later, |
| 643 | // but helps to avoid a lot of pointless work if we're going to skip it. |
cdalton | 91e457d | 2016-02-17 11:10:16 -0800 | [diff] [blame] | 644 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, SkOSPath::Basename(path).c_str())) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 645 | return nullptr; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 646 | } |
| 647 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 648 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 649 | if (stream.get() == nullptr) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 650 | SkDebugf("Could not read %s.\n", path); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 651 | return nullptr; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 652 | } |
| 653 | |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 654 | return SkPicture::MakeFromStream(stream.get()); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 655 | } |
| 656 | |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 657 | static sk_sp<SkPicture> ReadSVGPicture(const char* path) { |
| 658 | SkFILEStream stream(path); |
| 659 | if (!stream.isValid()) { |
| 660 | SkDebugf("Could not read %s.\n", path); |
| 661 | return nullptr; |
| 662 | } |
| 663 | |
fmalita | e1baa7c | 2016-09-14 12:04:30 -0700 | [diff] [blame] | 664 | sk_sp<SkSVGDOM> svgDom = SkSVGDOM::MakeFromStream(stream); |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 665 | if (!svgDom) { |
| 666 | SkDebugf("Could not parse %s.\n", path); |
| 667 | return nullptr; |
| 668 | } |
| 669 | |
fmalita | e1baa7c | 2016-09-14 12:04:30 -0700 | [diff] [blame] | 670 | // Use the intrinsic SVG size if available, otherwise fall back to a default value. |
| 671 | static const SkSize kDefaultContainerSize = SkSize::Make(128, 128); |
| 672 | if (svgDom->containerSize().isEmpty()) { |
| 673 | svgDom->setContainerSize(kDefaultContainerSize); |
| 674 | } |
| 675 | |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 676 | SkPictureRecorder recorder; |
fmalita | e1baa7c | 2016-09-14 12:04:30 -0700 | [diff] [blame] | 677 | svgDom->render(recorder.beginRecording(svgDom->containerSize().width(), |
| 678 | svgDom->containerSize().height())); |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 679 | return recorder.finishRecordingAsPicture(); |
| 680 | } |
| 681 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 682 | Benchmark* next() { |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 683 | SkAutoTDelete<Benchmark> bench; |
| 684 | do { |
| 685 | bench.reset(this->rawNext()); |
| 686 | if (!bench) { |
| 687 | return nullptr; |
| 688 | } |
| 689 | } while(SkCommandLineFlags::ShouldSkip(FLAGS_sourceType, fSourceType) || |
| 690 | SkCommandLineFlags::ShouldSkip(FLAGS_benchType, fBenchType)); |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 691 | return bench.release(); |
mtklein | 65dfd2f | 2016-02-03 10:40:54 -0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | Benchmark* rawNext() { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 695 | if (fBenches) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 696 | Benchmark* bench = fBenches->factory()(nullptr); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 697 | fBenches = fBenches->next(); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 698 | fSourceType = "bench"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 699 | fBenchType = "micro"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 700 | return bench; |
| 701 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 702 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 703 | while (fGMs) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 704 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 705 | fGMs = fGMs->next(); |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 706 | if (gm->runAsBench()) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 707 | fSourceType = "gm"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 708 | fBenchType = "micro"; |
mtklein | 18300a3 | 2016-03-16 13:53:35 -0700 | [diff] [blame] | 709 | return new GMBench(gm.release()); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 710 | } |
| 711 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 712 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 713 | // First add all .skps as RecordingBenches. |
| 714 | while (fCurrentRecording < fSKPs.count()) { |
| 715 | const SkString& path = fSKPs[fCurrentRecording++]; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 716 | sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
| 717 | if (!pic) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 718 | continue; |
| 719 | } |
| 720 | SkString name = SkOSPath::Basename(path.c_str()); |
| 721 | fSourceType = "skp"; |
| 722 | fBenchType = "recording"; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 723 | fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic.get())); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 724 | fSKPOps = pic->approximateOpCount(); |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 725 | return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh, FLAGS_lite); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | // Then once each for each scale as SKPBenches (playback). |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 729 | while (fCurrentScale < fScales.count()) { |
| 730 | while (fCurrentSKP < fSKPs.count()) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 731 | const SkString& path = fSKPs[fCurrentSKP]; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 732 | sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
| 733 | if (!pic) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 734 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 735 | continue; |
| 736 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 737 | |
| 738 | while (fCurrentUseMPD < fUseMPDs.count()) { |
| 739 | if (FLAGS_bbh) { |
| 740 | // The SKP we read off disk doesn't have a BBH. Re-record so it grows one. |
| 741 | SkRTreeFactory factory; |
| 742 | SkPictureRecorder recorder; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 743 | pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 744 | pic->cullRect().height(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 745 | &factory, |
robertphillips | dda5445 | 2016-07-13 13:27:16 -0700 | [diff] [blame] | 746 | 0)); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 747 | pic = recorder.finishRecordingAsPicture(); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 748 | } |
| 749 | SkString name = SkOSPath::Basename(path.c_str()); |
| 750 | fSourceType = "skp"; |
| 751 | fBenchType = "playback"; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 752 | return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale], |
| 753 | fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 754 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 755 | fCurrentUseMPD = 0; |
| 756 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 757 | } |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 758 | |
| 759 | while (fCurrentSVG++ < fSVGs.count()) { |
| 760 | const char* path = fSVGs[fCurrentSVG - 1].c_str(); |
| 761 | if (sk_sp<SkPicture> pic = ReadSVGPicture(path)) { |
| 762 | fSourceType = "svg"; |
| 763 | fBenchType = "playback"; |
| 764 | return new SKPBench(SkOSPath::Basename(path).c_str(), pic.get(), fClip, |
| 765 | fScales[fCurrentScale], false, FLAGS_loopSKP); |
| 766 | } |
| 767 | } |
| 768 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 769 | fCurrentSKP = 0; |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 770 | fCurrentSVG = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 771 | fCurrentScale++; |
| 772 | } |
| 773 | |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 774 | // Now loop over each skp again if we have an animation |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 775 | if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 776 | while (fCurrentAnimSKP < fSKPs.count()) { |
| 777 | const SkString& path = fSKPs[fCurrentAnimSKP]; |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 778 | sk_sp<SkPicture> pic = ReadPicture(path.c_str()); |
| 779 | if (!pic) { |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 780 | fCurrentAnimSKP++; |
| 781 | continue; |
| 782 | } |
| 783 | |
| 784 | fCurrentAnimSKP++; |
| 785 | SkString name = SkOSPath::Basename(path.c_str()); |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 786 | SkAutoTUnref<SKPAnimationBench::Animation> animation( |
| 787 | SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs)); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 788 | return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation, |
| 789 | FLAGS_loopSKP); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 793 | for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 794 | fSourceType = "image"; |
| 795 | fBenchType = "skcodec"; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 796 | const SkString& path = fImages[fCurrentCodec]; |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 797 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 798 | continue; |
| 799 | } |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 800 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 801 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 802 | if (!codec) { |
| 803 | // Nothing to time. |
msarett | 9d9725c | 2015-04-24 11:41:55 -0700 | [diff] [blame] | 804 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 805 | continue; |
| 806 | } |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 807 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 808 | while (fCurrentColorType < fColorTypes.count()) { |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 809 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 810 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 811 | SkAlphaType alphaType = codec->getInfo().alphaType(); |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 812 | if (FLAGS_simpleCodec) { |
| 813 | if (kUnpremul_SkAlphaType == alphaType) { |
| 814 | alphaType = kPremul_SkAlphaType; |
| 815 | } |
| 816 | |
| 817 | fCurrentColorType++; |
| 818 | } else { |
| 819 | switch (alphaType) { |
| 820 | case kOpaque_SkAlphaType: |
| 821 | // We only need to test one alpha type (opaque). |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 822 | fCurrentColorType++; |
msarett | 67cb666 | 2016-06-21 08:49:26 -0700 | [diff] [blame] | 823 | break; |
| 824 | case kUnpremul_SkAlphaType: |
| 825 | case kPremul_SkAlphaType: |
| 826 | if (0 == fCurrentAlphaType) { |
| 827 | // Test unpremul first. |
| 828 | alphaType = kUnpremul_SkAlphaType; |
| 829 | fCurrentAlphaType++; |
| 830 | } else { |
| 831 | // Test premul. |
| 832 | alphaType = kPremul_SkAlphaType; |
| 833 | fCurrentAlphaType = 0; |
| 834 | fCurrentColorType++; |
| 835 | } |
| 836 | break; |
| 837 | default: |
| 838 | SkASSERT(false); |
| 839 | fCurrentColorType++; |
| 840 | break; |
| 841 | } |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 842 | } |
| 843 | |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 844 | // Make sure we can decode to this color type and alpha type. |
| 845 | SkImageInfo info = |
| 846 | codec->getInfo().makeColorType(colorType).makeAlphaType(alphaType); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 847 | const size_t rowBytes = info.minRowBytes(); |
| 848 | SkAutoMalloc storage(info.getSafeSize(rowBytes)); |
| 849 | |
| 850 | // Used if fCurrentColorType is kIndex_8_SkColorType |
| 851 | int colorCount = 256; |
| 852 | SkPMColor colors[256]; |
| 853 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 854 | const SkCodec::Result result = codec->getPixels( |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 855 | info, storage.get(), rowBytes, nullptr, colors, |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 856 | &colorCount); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 857 | switch (result) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 858 | case SkCodec::kSuccess: |
| 859 | case SkCodec::kIncompleteInput: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 860 | return new CodecBench(SkOSPath::Basename(path.c_str()), |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 861 | encoded.get(), colorType, alphaType); |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 862 | case SkCodec::kInvalidConversion: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 863 | // This is okay. Not all conversions are valid. |
| 864 | break; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 865 | default: |
| 866 | // This represents some sort of failure. |
| 867 | SkASSERT(false); |
| 868 | break; |
| 869 | } |
| 870 | } |
| 871 | fCurrentColorType = 0; |
| 872 | } |
| 873 | |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 874 | // Run AndroidCodecBenches |
| 875 | const int sampleSizes[] = { 2, 4, 8 }; |
| 876 | for (; fCurrentAndroidCodec < fImages.count(); fCurrentAndroidCodec++) { |
| 877 | fSourceType = "image"; |
| 878 | fBenchType = "skandroidcodec"; |
| 879 | |
| 880 | const SkString& path = fImages[fCurrentAndroidCodec]; |
| 881 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 882 | continue; |
| 883 | } |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 884 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 885 | SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded)); |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 886 | if (!codec) { |
| 887 | // Nothing to time. |
| 888 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
| 889 | continue; |
| 890 | } |
| 891 | |
| 892 | while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { |
| 893 | int sampleSize = sampleSizes[fCurrentSampleSize]; |
| 894 | fCurrentSampleSize++; |
| 895 | if (10 * sampleSize > SkTMin(codec->getInfo().width(), codec->getInfo().height())) { |
| 896 | // Avoid benchmarking scaled decodes of already small images. |
| 897 | break; |
| 898 | } |
| 899 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 900 | return new AndroidCodecBench(SkOSPath::Basename(path.c_str()), |
| 901 | encoded.get(), sampleSize); |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 902 | } |
| 903 | fCurrentSampleSize = 0; |
| 904 | } |
| 905 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 906 | // Run the BRDBenches |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 907 | // We intend to create benchmarks that model the use cases in |
| 908 | // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512 |
| 909 | // tiles. The image can be translated freely, so the location of a tile may be anywhere in |
| 910 | // the image. For that reason, we will benchmark decodes in five representative locations |
| 911 | // in the image. Additionally, this use case utilizes power of two scaling, so we will |
| 912 | // test on power of two sample sizes. The output tile is always 512x512, so, when a |
| 913 | // sampleSize is used, the size of the subset that is decoded is always |
| 914 | // (sampleSize*512)x(sampleSize*512). |
| 915 | // There are a few good reasons to only test on power of two sample sizes at this time: |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 916 | // All use cases we are aware of only scale by powers of two. |
| 917 | // PNG decodes use the indicated sampling strategy regardless of the sample size, so |
| 918 | // these tests are sufficient to provide good coverage of our scaling options. |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 919 | const uint32_t brdSampleSizes[] = { 1, 2, 4, 8, 16 }; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 920 | const uint32_t minOutputSize = 512; |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 921 | for (; fCurrentBRDImage < fImages.count(); fCurrentBRDImage++) { |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 922 | fSourceType = "image"; |
| 923 | fBenchType = "BRD"; |
| 924 | |
mtklein | 6f0ff91 | 2016-01-11 09:04:21 -0800 | [diff] [blame] | 925 | const SkString& path = fImages[fCurrentBRDImage]; |
| 926 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path.c_str())) { |
| 927 | continue; |
| 928 | } |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 929 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 930 | while (fCurrentColorType < fColorTypes.count()) { |
| 931 | while (fCurrentSampleSize < (int) SK_ARRAY_COUNT(brdSampleSizes)) { |
| 932 | while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 933 | |
bungeman | 38d909e | 2016-08-02 14:40:46 -0700 | [diff] [blame] | 934 | sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str())); |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 935 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 936 | uint32_t sampleSize = brdSampleSizes[fCurrentSampleSize]; |
| 937 | int currentSubsetType = fCurrentSubsetType++; |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 938 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 939 | int width = 0; |
| 940 | int height = 0; |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 941 | if (!valid_brd_bench(encoded, colorType, sampleSize, minOutputSize, |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 942 | &width, &height)) { |
| 943 | break; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 944 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 945 | |
| 946 | SkString basename = SkOSPath::Basename(path.c_str()); |
| 947 | SkIRect subset; |
| 948 | const uint32_t subsetSize = sampleSize * minOutputSize; |
| 949 | switch (currentSubsetType) { |
| 950 | case kTopLeft_SubsetType: |
| 951 | basename.append("_TopLeft"); |
| 952 | subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize); |
| 953 | break; |
| 954 | case kTopRight_SubsetType: |
| 955 | basename.append("_TopRight"); |
| 956 | subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize, |
| 957 | subsetSize); |
| 958 | break; |
| 959 | case kMiddle_SubsetType: |
| 960 | basename.append("_Middle"); |
| 961 | subset = SkIRect::MakeXYWH((width - subsetSize) / 2, |
| 962 | (height - subsetSize) / 2, subsetSize, subsetSize); |
| 963 | break; |
| 964 | case kBottomLeft_SubsetType: |
| 965 | basename.append("_BottomLeft"); |
| 966 | subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize, |
| 967 | subsetSize); |
| 968 | break; |
| 969 | case kBottomRight_SubsetType: |
| 970 | basename.append("_BottomRight"); |
| 971 | subset = SkIRect::MakeXYWH(width - subsetSize, |
| 972 | height - subsetSize, subsetSize, subsetSize); |
| 973 | break; |
| 974 | default: |
| 975 | SkASSERT(false); |
| 976 | } |
| 977 | |
| 978 | return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(), |
| 979 | colorType, sampleSize, subset); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 980 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 981 | fCurrentSubsetType = 0; |
| 982 | fCurrentSampleSize++; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 983 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 984 | fCurrentSampleSize = 0; |
| 985 | fCurrentColorType++; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 986 | } |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 987 | fCurrentColorType = 0; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 988 | } |
| 989 | |
msarett | 2cee902 | 2016-06-03 08:25:21 -0700 | [diff] [blame] | 990 | while (fCurrentColorImage < fColorImages.count()) { |
| 991 | fSourceType = "colorimage"; |
| 992 | fBenchType = "skcolorcodec"; |
| 993 | const SkString& path = fColorImages[fCurrentColorImage]; |
| 994 | fCurrentColorImage++; |
| 995 | sk_sp<SkData> encoded = SkData::MakeFromFileName(path.c_str()); |
| 996 | if (encoded) { |
| 997 | return new ColorCodecBench(SkOSPath::Basename(path.c_str()).c_str(), |
| 998 | std::move(encoded)); |
| 999 | } else { |
| 1000 | SkDebugf("Could not read file %s.\n", path.c_str()); |
| 1001 | } |
| 1002 | } |
| 1003 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1004 | return nullptr; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1005 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1006 | |
| 1007 | void fillCurrentOptions(ResultsWriter* log) const { |
| 1008 | log->configOption("source_type", fSourceType); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 1009 | log->configOption("bench_type", fBenchType); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1010 | if (0 == strcmp(fSourceType, "skp")) { |
| 1011 | log->configOption("clip", |
| 1012 | SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 1013 | fClip.fRight, fClip.fBottom).c_str()); |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 1014 | SkASSERT_RELEASE(fCurrentScale < fScales.count()); // debugging paranoia |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1015 | log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str()); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1016 | if (fCurrentUseMPD > 0) { |
| 1017 | SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
| 1018 | log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false"); |
| 1019 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1020 | } |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1021 | if (0 == strcmp(fBenchType, "recording")) { |
| 1022 | log->metric("bytes", fSKPBytes); |
| 1023 | log->metric("ops", fSKPOps); |
| 1024 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1027 | private: |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1028 | enum SubsetType { |
| 1029 | kTopLeft_SubsetType = 0, |
| 1030 | kTopRight_SubsetType = 1, |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 1031 | kMiddle_SubsetType = 2, |
| 1032 | kBottomLeft_SubsetType = 3, |
| 1033 | kBottomRight_SubsetType = 4, |
| 1034 | kTranslate_SubsetType = 5, |
| 1035 | kZoom_SubsetType = 6, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1036 | kLast_SubsetType = kZoom_SubsetType, |
| 1037 | kLastSingle_SubsetType = kBottomRight_SubsetType, |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1038 | }; |
| 1039 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1040 | const BenchRegistry* fBenches; |
| 1041 | const skiagm::GMRegistry* fGMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1042 | SkIRect fClip; |
| 1043 | SkTArray<SkScalar> fScales; |
| 1044 | SkTArray<SkString> fSKPs; |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 1045 | SkTArray<SkString> fSVGs; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1046 | SkTArray<bool> fUseMPDs; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 1047 | SkTArray<SkString> fImages; |
msarett | 2cee902 | 2016-06-03 08:25:21 -0700 | [diff] [blame] | 1048 | SkTArray<SkString> fColorImages; |
msarett | 74deb98 | 2015-10-20 16:45:56 -0700 | [diff] [blame] | 1049 | SkTArray<SkColorType, true> fColorTypes; |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 1050 | SkScalar fZoomMax; |
| 1051 | double fZoomPeriodMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1052 | |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1053 | double fSKPBytes, fSKPOps; |
| 1054 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 1055 | const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 1056 | const char* fBenchType; // How we bench it: micro, recording, playback, ... |
| 1057 | int fCurrentRecording; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1058 | int fCurrentScale; |
| 1059 | int fCurrentSKP; |
fmalita | 6519c21 | 2016-09-14 08:05:17 -0700 | [diff] [blame] | 1060 | int fCurrentSVG; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1061 | int fCurrentUseMPD; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 1062 | int fCurrentCodec; |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 1063 | int fCurrentAndroidCodec; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1064 | int fCurrentBRDImage; |
msarett | 2cee902 | 2016-06-03 08:25:21 -0700 | [diff] [blame] | 1065 | int fCurrentColorImage; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 1066 | int fCurrentColorType; |
msarett | c7796b9 | 2016-01-07 14:20:20 -0800 | [diff] [blame] | 1067 | int fCurrentAlphaType; |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1068 | int fCurrentSubsetType; |
msarett | 8445102 | 2016-02-11 06:45:51 -0800 | [diff] [blame] | 1069 | int fCurrentSampleSize; |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 1070 | int fCurrentAnimSKP; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1071 | }; |
| 1072 | |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1073 | // Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung. |
| 1074 | // This prints something every once in a while so that it knows we're still working. |
| 1075 | static void start_keepalive() { |
| 1076 | struct Loop { |
| 1077 | static void forever(void*) { |
| 1078 | for (;;) { |
| 1079 | static const int kSec = 1200; |
| 1080 | #if defined(SK_BUILD_FOR_WIN) |
| 1081 | Sleep(kSec * 1000); |
| 1082 | #else |
| 1083 | sleep(kSec); |
| 1084 | #endif |
| 1085 | SkDebugf("\nBenchmarks still running...\n"); |
| 1086 | } |
| 1087 | } |
| 1088 | }; |
| 1089 | static SkThread* intentionallyLeaked = new SkThread(Loop::forever); |
| 1090 | intentionallyLeaked->start(); |
| 1091 | } |
| 1092 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1093 | int nanobench_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1094 | int nanobench_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1095 | SetupCrashHandler(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1096 | SkAutoGraphics ag; |
mtklein | cc29d26 | 2015-07-09 10:04:56 -0700 | [diff] [blame] | 1097 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1098 | |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1099 | #if SK_SUPPORT_GPU |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 1100 | GrContextOptions grContextOpts; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1101 | gGrFactory.reset(new GrContextFactory(grContextOpts)); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1102 | #endif |
| 1103 | |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1104 | if (FLAGS_veryVerbose) { |
| 1105 | FLAGS_verbose = true; |
| 1106 | } |
| 1107 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1108 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1109 | FLAGS_samples = 1; |
| 1110 | FLAGS_gpuFrameLag = 0; |
| 1111 | } |
| 1112 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1113 | if (!FLAGS_writePath.isEmpty()) { |
| 1114 | SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
| 1115 | if (!sk_mkdir(FLAGS_writePath[0])) { |
| 1116 | SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1117 | FLAGS_writePath.set(0, nullptr); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1118 | } |
| 1119 | } |
| 1120 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1121 | SkAutoTDelete<ResultsWriter> log(new ResultsWriter); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1122 | if (!FLAGS_outResultsFile.isEmpty()) { |
mtklein | 5352015 | 2016-01-20 09:53:59 -0800 | [diff] [blame] | 1123 | #if defined(SK_RELEASE) |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1124 | log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0])); |
mtklein | 5352015 | 2016-01-20 09:53:59 -0800 | [diff] [blame] | 1125 | #else |
| 1126 | SkDebugf("I'm ignoring --outResultsFile because this is a Debug build."); |
| 1127 | return 1; |
| 1128 | #endif |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1129 | } |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1130 | |
| 1131 | if (1 == FLAGS_properties.count() % 2) { |
| 1132 | SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n"); |
| 1133 | return 1; |
| 1134 | } |
| 1135 | for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
| 1136 | log->property(FLAGS_properties[i-1], FLAGS_properties[i]); |
| 1137 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1138 | |
| 1139 | if (1 == FLAGS_key.count() % 2) { |
| 1140 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 1141 | return 1; |
| 1142 | } |
| 1143 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1144 | log->key(FLAGS_key[i-1], FLAGS_key[i]); |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame] | 1145 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1146 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1147 | const double overhead = estimate_timer_overhead(); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1148 | SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); |
Mike Klein | 9129477 | 2014-07-16 19:59:32 -0400 | [diff] [blame] | 1149 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1150 | SkTArray<double> samples; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 1151 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1152 | if (kAutoTuneLoops != FLAGS_loops) { |
| 1153 | SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1154 | } else if (FLAGS_quiet) { |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1155 | SkDebugf("! -> high variance, ? -> moderate variance\n"); |
| 1156 | SkDebugf(" micros \tbench\n"); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1157 | } else if (FLAGS_ms) { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1158 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1159 | } else { |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1160 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |
qiankun.miao | 8247ec3 | 2014-09-09 19:24:36 -0700 | [diff] [blame] | 1161 | FLAGS_samples, "samples"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1164 | SkTArray<Config> configs; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 1165 | create_configs(&configs); |
| 1166 | |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 1167 | #ifdef THERMAL_MANAGER_SUPPORTED |
| 1168 | int tmEnabled, tmThreshold, tmSleepTimeMs, tmTimeoutMs; |
| 1169 | if (4 != sscanf(FLAGS_useThermalManager[0], "%d,%d,%d,%d", |
| 1170 | &tmEnabled, &tmThreshold, &tmSleepTimeMs, &tmTimeoutMs)) { |
| 1171 | SkDebugf("Can't parse %s from --useThermalManager.\n", FLAGS_useThermalManager[0]); |
| 1172 | exit(1); |
| 1173 | } |
| 1174 | ThermalManager tm(tmThreshold, tmSleepTimeMs, tmTimeoutMs); |
| 1175 | #endif |
| 1176 | |
msarett | c149f0e | 2016-01-04 11:35:43 -0800 | [diff] [blame] | 1177 | if (FLAGS_keepAlive) { |
| 1178 | start_keepalive(); |
| 1179 | } |
| 1180 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1181 | int runs = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1182 | BenchmarkStream benchStream; |
| 1183 | while (Benchmark* b = benchStream.next()) { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1184 | SkAutoTDelete<Benchmark> bench(b); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1185 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1186 | continue; |
| 1187 | } |
| 1188 | |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1189 | if (!configs.empty()) { |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1190 | log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY); |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 1191 | bench->delayedSetup(); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1192 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1193 | for (int i = 0; i < configs.count(); ++i) { |
joshualitt | 3ebd050 | 2016-02-09 07:18:08 -0800 | [diff] [blame] | 1194 | #ifdef THERMAL_MANAGER_SUPPORTED |
| 1195 | if (tmEnabled && !tm.coolOffIfNecessary()) { |
| 1196 | SkDebugf("Could not cool off, timings will be throttled\n"); |
| 1197 | } |
| 1198 | #endif |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1199 | Target* target = is_enabled(b, configs[i]); |
| 1200 | if (!target) { |
| 1201 | continue; |
| 1202 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1203 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1204 | // During HWUI output this canvas may be nullptr. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1205 | SkCanvas* canvas = target->getCanvas(); |
svaisanen | c47635e | 2016-01-28 06:05:43 -0800 | [diff] [blame] | 1206 | const char* config = target->config.name.c_str(); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1207 | |
brianosman | 7a5ada8 | 2016-02-08 13:49:12 -0800 | [diff] [blame] | 1208 | if (FLAGS_pre_log || FLAGS_dryRun) { |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 1209 | SkDebugf("Running %s\t%s\n" |
| 1210 | , bench->getUniqueName() |
| 1211 | , config); |
brianosman | 7a5ada8 | 2016-02-08 13:49:12 -0800 | [diff] [blame] | 1212 | if (FLAGS_dryRun) { |
| 1213 | continue; |
| 1214 | } |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1217 | target->setup(); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1218 | bench->perCanvasPreDraw(canvas); |
| 1219 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1220 | int maxFrameLag; |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1221 | int loops = target->needsFrameTiming(&maxFrameLag) |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1222 | ? setup_gpu_bench(target, bench.get(), maxFrameLag) |
| 1223 | : setup_cpu_bench(overhead, target, bench.get()); |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1224 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1225 | if (FLAGS_ms) { |
| 1226 | samples.reset(); |
| 1227 | auto stop = now_ms() + FLAGS_ms; |
| 1228 | do { |
| 1229 | samples.push_back(time(loops, bench, target) / loops); |
| 1230 | } while (now_ms() < stop); |
| 1231 | } else { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1232 | samples.reset(FLAGS_samples); |
| 1233 | for (int s = 0; s < FLAGS_samples; s++) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1234 | samples[s] = time(loops, bench, target) / loops; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1235 | } |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1236 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1237 | |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1238 | #if SK_SUPPORT_GPU |
| 1239 | SkTArray<SkString> keys; |
| 1240 | SkTArray<double> values; |
| 1241 | bool gpuStatsDump = FLAGS_gpuStatsDump && Benchmark::kGPU_Backend == configs[i].backend; |
| 1242 | if (gpuStatsDump) { |
| 1243 | // TODO cache stats |
| 1244 | bench->getGpuStats(canvas, &keys, &values); |
| 1245 | } |
| 1246 | #endif |
| 1247 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1248 | bench->perCanvasPostDraw(canvas); |
| 1249 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1250 | if (Benchmark::kNonRendering_Backend != target->config.backend && |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 1251 | !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1252 | SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1253 | pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName()); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1254 | pngFilename.append(".png"); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1255 | write_canvas_png(target, pngFilename); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | if (kFailedLoops == loops) { |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 1259 | // Can't be timed. A warning note has already been printed. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1260 | cleanup_run(target); |
Mike Klein | e363136 | 2014-07-15 17:56:37 -0400 | [diff] [blame] | 1261 | continue; |
| 1262 | } |
| 1263 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1264 | Stats stats(samples); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1265 | log->config(config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1266 | log->configOption("name", bench->getName()); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1267 | benchStream.fillCurrentOptions(log.get()); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1268 | target->fillOptions(log.get()); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1269 | log->metric("min_ms", stats.min); |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1270 | #if SK_SUPPORT_GPU |
| 1271 | if (gpuStatsDump) { |
| 1272 | // dump to json, only SKPBench currently returns valid keys / values |
| 1273 | SkASSERT(keys.count() == values.count()); |
| 1274 | for (int i = 0; i < keys.count(); i++) { |
| 1275 | log->metric(keys[i].c_str(), values[i]); |
| 1276 | } |
| 1277 | } |
| 1278 | #endif |
| 1279 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1280 | if (runs++ % FLAGS_flushEvery == 0) { |
| 1281 | log->flush(); |
| 1282 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1283 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1284 | if (kAutoTuneLoops != FLAGS_loops) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1285 | if (configs.count() == 1) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1286 | config = ""; // Only print the config if we run the same bench on more than one. |
| 1287 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1288 | SkDebugf("%4d/%-4dMB\t%s\t%s\n" |
| 1289 | , sk_tools::getCurrResidentSetSizeMB() |
| 1290 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | 53d2562 | 2014-09-18 07:39:42 -0700 | [diff] [blame] | 1291 | , bench->getUniqueName() |
| 1292 | , config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1293 | } else if (FLAGS_quiet) { |
mtklein | 66cfcff | 2015-12-04 06:35:30 -0800 | [diff] [blame] | 1294 | const char* mark = " "; |
| 1295 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
| 1296 | if (stddev_percent > 5) mark = "?"; |
| 1297 | if (stddev_percent > 10) mark = "!"; |
| 1298 | |
| 1299 | SkDebugf("%10.2f %s\t%s\t%s\n", |
| 1300 | stats.median*1e3, mark, bench->getUniqueName(), config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1301 | } else { |
| 1302 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1303 | SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" |
| 1304 | , sk_tools::getCurrResidentSetSizeMB() |
| 1305 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1306 | , loops |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1307 | , HUMANIZE(stats.min) |
| 1308 | , HUMANIZE(stats.median) |
| 1309 | , HUMANIZE(stats.mean) |
| 1310 | , HUMANIZE(stats.max) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1311 | , stddev_percent |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1312 | , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1313 | , config |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1314 | , bench->getUniqueName() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1315 | ); |
| 1316 | } |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1317 | |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 1318 | #if SK_SUPPORT_GPU |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1319 | if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1320 | GrContext* context = gGrFactory->get(configs[i].ctxType, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1321 | configs[i].ctxOptions); |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1322 | context->printCacheStats(); |
| 1323 | context->printGpuStats(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1324 | } |
| 1325 | #endif |
joshualitt | e45c81c | 2015-12-02 09:05:37 -0800 | [diff] [blame] | 1326 | |
cdalton | 2c56ba5 | 2015-06-26 13:32:53 -0700 | [diff] [blame] | 1327 | if (FLAGS_verbose) { |
| 1328 | SkDebugf("Samples: "); |
| 1329 | for (int i = 0; i < samples.count(); i++) { |
| 1330 | SkDebugf("%s ", HUMANIZE(samples[i])); |
| 1331 | } |
| 1332 | SkDebugf("%s\n", bench->getUniqueName()); |
| 1333 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1334 | cleanup_run(target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1335 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1336 | } |
| 1337 | |
mtklein | e109145 | 2014-12-04 10:47:02 -0800 | [diff] [blame] | 1338 | log->bench("memory_usage", 0,0); |
| 1339 | log->config("meta"); |
| 1340 | log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB()); |
| 1341 | |
joshualitt | e0b19d4 | 2015-03-26 10:41:02 -0700 | [diff] [blame] | 1342 | #if SK_SUPPORT_GPU |
| 1343 | // Make sure we clean up the global GrContextFactory here, otherwise we might race with the |
| 1344 | // SkEventTracer destructor |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1345 | gGrFactory.reset(nullptr); |
joshualitt | e0b19d4 | 2015-03-26 10:41:02 -0700 | [diff] [blame] | 1346 | #endif |
| 1347 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1348 | return 0; |
| 1349 | } |
| 1350 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1351 | #if !defined SK_BUILD_FOR_IOS |
| 1352 | int main(int argc, char** argv) { |
| 1353 | SkCommandLineFlags::Parse(argc, argv); |
| 1354 | return nanobench_main(); |
| 1355 | } |
| 1356 | #endif |