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