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