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