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