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