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 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 10 | #include "Benchmark.h" |
| 11 | #include "CrashHandler.h" |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 12 | #include "DecodingBench.h" |
| 13 | #include "DecodingSubsetBench.h" |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 14 | #include "GMBench.h" |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 15 | #include "ProcStats.h" |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 16 | #include "ResultsWriter.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 17 | #include "RecordingBench.h" |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 18 | #include "SKPBench.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 19 | #include "Stats.h" |
| 20 | #include "Timer.h" |
| 21 | |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 22 | #include "SkBBoxHierarchy.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 23 | #include "SkCanvas.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 24 | #include "SkCommonFlags.h" |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 25 | #include "SkData.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 26 | #include "SkForceLinking.h" |
| 27 | #include "SkGraphics.h" |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 28 | #include "SkOSFile.h" |
| 29 | #include "SkPictureRecorder.h" |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 30 | #include "SkPictureUtils.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 31 | #include "SkString.h" |
| 32 | #include "SkSurface.h" |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 33 | #include "SkTaskGroup.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 34 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 35 | #if SK_SUPPORT_GPU |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 36 | #include "gl/GrGLDefines.h" |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 37 | #include "GrContextFactory.h" |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 38 | SkAutoTDelete<GrContextFactory> gGrFactory; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 39 | #endif |
| 40 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 41 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 42 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 43 | static const int kAutoTuneLoops = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 44 | |
mtklein | b511042 | 2014-08-07 15:20:02 -0700 | [diff] [blame] | 45 | static const int kDefaultLoops = |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 46 | #ifdef SK_DEBUG |
| 47 | 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 48 | #else |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 49 | kAutoTuneLoops; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 50 | #endif |
| 51 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 52 | static SkString loops_help_txt() { |
| 53 | SkString help; |
| 54 | help.printf("Number of times to run each bench. Set this to %d to auto-" |
| 55 | "tune for each bench. Timings are only reported when auto-tuning.", |
| 56 | kAutoTuneLoops); |
| 57 | return help; |
| 58 | } |
| 59 | |
| 60 | DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str()); |
| 61 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 62 | DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); |
| 63 | DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); |
| 64 | DEFINE_double(overheadGoal, 0.0001, |
| 65 | "Loop until timer overhead is at most this fraction of our measurments."); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 66 | DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
| 67 | DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allows to lag."); |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 68 | DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " |
| 69 | "software path rendering."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 70 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 71 | DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 72 | DEFINE_int32(maxCalibrationAttempts, 3, |
| 73 | "Try up to this many times to guess loops for a bench, or skip the bench."); |
| 74 | DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 75 | DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 76 | DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 77 | DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 78 | DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 79 | DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 80 | DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 81 | DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 82 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 83 | static SkString humanize(double ms) { |
mtklein | dc5bbab | 2014-09-24 06:34:09 -0700 | [diff] [blame] | 84 | if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 85 | return HumanizeMs(ms); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 86 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 87 | #define HUMANIZE(ms) humanize(ms).c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 88 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 89 | static double time(int loops, Benchmark* bench, SkCanvas* canvas, SkGLContext* gl) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 90 | if (canvas) { |
| 91 | canvas->clear(SK_ColorWHITE); |
| 92 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 93 | WallTimer timer; |
| 94 | timer.start(); |
| 95 | if (bench) { |
| 96 | bench->draw(loops, canvas); |
| 97 | } |
| 98 | if (canvas) { |
| 99 | canvas->flush(); |
| 100 | } |
| 101 | #if SK_SUPPORT_GPU |
| 102 | if (gl) { |
| 103 | SK_GL(*gl, Flush()); |
| 104 | gl->swapBuffers(); |
| 105 | } |
| 106 | #endif |
| 107 | timer.end(); |
| 108 | return timer.fWall; |
| 109 | } |
| 110 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 111 | static double estimate_timer_overhead() { |
| 112 | double overhead = 0; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 113 | for (int i = 0; i < FLAGS_overheadLoops; i++) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 114 | overhead += time(1, NULL, NULL, NULL); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 115 | } |
| 116 | return overhead / FLAGS_overheadLoops; |
| 117 | } |
| 118 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 119 | static int detect_forever_loops(int loops) { |
| 120 | // look for a magic run-forever value |
| 121 | if (loops < 0) { |
| 122 | loops = SK_MaxS32; |
| 123 | } |
| 124 | return loops; |
| 125 | } |
| 126 | |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 127 | static int clamp_loops(int loops) { |
| 128 | if (loops < 1) { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 129 | SkDebugf("ERROR: clamping loops from %d to 1. " |
| 130 | "There's probably something wrong with the bench.\n", loops); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 131 | return 1; |
| 132 | } |
| 133 | if (loops > FLAGS_maxLoops) { |
| 134 | SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops); |
| 135 | return FLAGS_maxLoops; |
| 136 | } |
| 137 | return loops; |
| 138 | } |
| 139 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 140 | static bool write_canvas_png(SkCanvas* canvas, const SkString& filename) { |
| 141 | if (filename.isEmpty()) { |
| 142 | return false; |
| 143 | } |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 144 | if (kUnknown_SkColorType == canvas->imageInfo().colorType()) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 145 | return false; |
| 146 | } |
| 147 | SkBitmap bmp; |
| 148 | bmp.setInfo(canvas->imageInfo()); |
| 149 | if (!canvas->readPixels(&bmp, 0, 0)) { |
| 150 | SkDebugf("Can't read canvas pixels.\n"); |
| 151 | return false; |
| 152 | } |
| 153 | SkString dir = SkOSPath::Dirname(filename.c_str()); |
| 154 | if (!sk_mkdir(dir.c_str())) { |
| 155 | SkDebugf("Can't make dir %s.\n", dir.c_str()); |
| 156 | return false; |
| 157 | } |
| 158 | SkFILEWStream stream(filename.c_str()); |
| 159 | if (!stream.isValid()) { |
| 160 | SkDebugf("Can't write %s.\n", filename.c_str()); |
| 161 | return false; |
| 162 | } |
| 163 | if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) { |
| 164 | SkDebugf("Can't encode a PNG.\n"); |
| 165 | return false; |
| 166 | } |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | static int kFailedLoops = -2; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 171 | static int cpu_bench(const double overhead, Benchmark* bench, SkCanvas* canvas, double* samples) { |
| 172 | // 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] | 173 | double bench_plus_overhead = 0.0; |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 174 | int round = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 175 | if (kAutoTuneLoops == FLAGS_loops) { |
| 176 | while (bench_plus_overhead < overhead) { |
| 177 | if (round++ == FLAGS_maxCalibrationAttempts) { |
| 178 | SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 179 | bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead)); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 180 | return kFailedLoops; |
| 181 | } |
| 182 | bench_plus_overhead = time(1, bench, canvas, NULL); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 183 | } |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 184 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 185 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 186 | // 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] | 187 | // We'll pick N to make timer overhead negligible: |
| 188 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 189 | // overhead |
| 190 | // ------------------------- < FLAGS_overheadGoal |
| 191 | // overhead + N * Bench Time |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 192 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 193 | // where bench_plus_overhead ≈ overhead + Bench Time. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 194 | // |
| 195 | // Doing some math, we get: |
| 196 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 197 | // (overhead / FLAGS_overheadGoal) - overhead |
| 198 | // ------------------------------------------ < N |
| 199 | // bench_plus_overhead - overhead) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 200 | // |
| 201 | // Luckily, this also works well in practice. :) |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 202 | int loops = FLAGS_loops; |
| 203 | if (kAutoTuneLoops == loops) { |
| 204 | const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 205 | const double denom = bench_plus_overhead - overhead; |
| 206 | loops = (int)ceil(numer / denom); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 207 | loops = clamp_loops(loops); |
| 208 | } else { |
| 209 | loops = detect_forever_loops(loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 210 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 211 | |
| 212 | for (int i = 0; i < FLAGS_samples; i++) { |
| 213 | samples[i] = time(loops, bench, canvas, NULL) / loops; |
| 214 | } |
| 215 | return loops; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 216 | } |
| 217 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 218 | #if SK_SUPPORT_GPU |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 219 | static void setup_gl(SkGLContext* gl) { |
| 220 | gl->makeCurrent(); |
| 221 | // Make sure we're done with whatever came before. |
| 222 | SK_GL(*gl, Finish()); |
| 223 | } |
| 224 | |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 225 | static int gpu_bench(SkGLContext* gl, |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 226 | Benchmark* bench, |
| 227 | SkCanvas* canvas, |
| 228 | double* samples) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 229 | // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs. |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 230 | int loops = FLAGS_loops; |
| 231 | if (kAutoTuneLoops == loops) { |
| 232 | loops = 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 233 | double elapsed = 0; |
| 234 | do { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 235 | if (1<<30 == loops) { |
| 236 | // We're about to wrap. Something's wrong with the bench. |
| 237 | loops = 0; |
| 238 | break; |
| 239 | } |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 240 | loops *= 2; |
| 241 | // If the GPU lets frames lag at all, we need to make sure we're timing |
| 242 | // _this_ round, not still timing last round. We force this by looping |
| 243 | // more times than any reasonable GPU will allow frames to lag. |
| 244 | for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 245 | elapsed = time(loops, bench, canvas, gl); |
| 246 | } |
| 247 | } while (elapsed < FLAGS_gpuMs); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 248 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 249 | // We've overshot at least a little. Scale back linearly. |
| 250 | loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 251 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 252 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 253 | // Might as well make sure we're not still timing our calibration. |
| 254 | SK_GL(*gl, Finish()); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 255 | } else { |
| 256 | loops = detect_forever_loops(loops); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 257 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 258 | |
| 259 | // Pretty much the same deal as the calibration: do some warmup to make |
| 260 | // sure we're timing steady-state pipelined frames. |
| 261 | for (int i = 0; i < FLAGS_gpuFrameLag; i++) { |
| 262 | time(loops, bench, canvas, gl); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 263 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 264 | |
| 265 | // Now, actually do the timing! |
| 266 | for (int i = 0; i < FLAGS_samples; i++) { |
| 267 | samples[i] = time(loops, bench, canvas, gl) / loops; |
| 268 | } |
| 269 | return loops; |
| 270 | } |
| 271 | #endif |
| 272 | |
| 273 | static SkString to_lower(const char* str) { |
| 274 | SkString lower(str); |
| 275 | for (size_t i = 0; i < lower.size(); i++) { |
| 276 | lower[i] = tolower(lower[i]); |
| 277 | } |
| 278 | return lower; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 279 | } |
| 280 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 281 | struct Config { |
| 282 | const char* name; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 283 | Benchmark::Backend backend; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 284 | SkColorType color; |
| 285 | SkAlphaType alpha; |
| 286 | int samples; |
| 287 | #if SK_SUPPORT_GPU |
| 288 | GrContextFactory::GLContextType ctxType; |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 289 | bool useDFText; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 290 | #else |
| 291 | int bogusInt; |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 292 | bool bogusBool; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 293 | #endif |
| 294 | }; |
| 295 | |
| 296 | struct Target { |
| 297 | explicit Target(const Config& c) : config(c) {} |
| 298 | const Config config; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 299 | SkAutoTDelete<SkSurface> surface; |
| 300 | #if SK_SUPPORT_GPU |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 301 | SkGLContext* gl; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 302 | #endif |
| 303 | }; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 304 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 305 | static bool is_cpu_config_allowed(const char* name) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 306 | for (int i = 0; i < FLAGS_config.count(); i++) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 307 | if (to_lower(FLAGS_config[i]).equals(name)) { |
| 308 | return true; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 309 | } |
| 310 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 311 | return false; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 312 | } |
| 313 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 314 | #if SK_SUPPORT_GPU |
| 315 | static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType, |
| 316 | int sampleCnt) { |
| 317 | if (!is_cpu_config_allowed(name)) { |
| 318 | return false; |
| 319 | } |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 320 | if (const GrContext* ctx = gGrFactory->get(ctxType)) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 321 | return sampleCnt <= ctx->getMaxSampleCount(); |
| 322 | } |
| 323 | return false; |
| 324 | } |
| 325 | #endif |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 326 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 327 | #if SK_SUPPORT_GPU |
| 328 | #define kBogusGLContextType GrContextFactory::kNative_GLContextType |
| 329 | #else |
| 330 | #define kBogusGLContextType 0 |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 331 | #endif |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 332 | |
| 333 | // Append all configs that are enabled and supported. |
| 334 | static void create_configs(SkTDArray<Config>* configs) { |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 335 | #define CPU_CONFIG(name, backend, color, alpha) \ |
| 336 | if (is_cpu_config_allowed(#name)) { \ |
| 337 | Config config = { #name, Benchmark::backend, color, alpha, 0, \ |
| 338 | kBogusGLContextType, false }; \ |
| 339 | configs->push(config); \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 340 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 341 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 342 | if (FLAGS_cpu) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 343 | CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType) |
| 344 | CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) |
| 345 | CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType) |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 346 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 347 | |
| 348 | #if SK_SUPPORT_GPU |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 349 | #define GPU_CONFIG(name, ctxType, samples, useDFText) \ |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 350 | if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \ |
| 351 | Config config = { \ |
| 352 | #name, \ |
| 353 | Benchmark::kGPU_Backend, \ |
| 354 | kN32_SkColorType, \ |
| 355 | kPremul_SkAlphaType, \ |
| 356 | samples, \ |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 357 | GrContextFactory::ctxType, \ |
| 358 | useDFText }; \ |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 359 | configs->push(config); \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 360 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 361 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 362 | if (FLAGS_gpu) { |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 363 | GPU_CONFIG(gpu, kNative_GLContextType, 0, false) |
| 364 | GPU_CONFIG(msaa4, kNative_GLContextType, 4, false) |
| 365 | GPU_CONFIG(msaa16, kNative_GLContextType, 16, false) |
| 366 | GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false) |
| 367 | GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false) |
| 368 | GPU_CONFIG(gpudft, kNative_GLContextType, 0, true) |
| 369 | GPU_CONFIG(debug, kDebug_GLContextType, 0, false) |
| 370 | GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false) |
bsalomon | 3b4d077 | 2014-08-06 10:52:33 -0700 | [diff] [blame] | 371 | #ifdef SK_ANGLE |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 372 | GPU_CONFIG(angle, kANGLE_GLContextType, 0, false) |
bsalomon | 3b4d077 | 2014-08-06 10:52:33 -0700 | [diff] [blame] | 373 | #endif |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 374 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 375 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 376 | } |
| 377 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 378 | // If bench is enabled for config, returns a Target* for it, otherwise NULL. |
| 379 | static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 380 | if (!bench->isSuitableFor(config.backend)) { |
| 381 | return NULL; |
| 382 | } |
| 383 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 384 | SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, |
| 385 | config.color, config.alpha); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 386 | |
| 387 | Target* target = new Target(config); |
| 388 | |
| 389 | if (Benchmark::kRaster_Backend == config.backend) { |
| 390 | target->surface.reset(SkSurface::NewRaster(info)); |
| 391 | } |
| 392 | #if SK_SUPPORT_GPU |
| 393 | else if (Benchmark::kGPU_Backend == config.backend) { |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 394 | uint32_t flags = config.useDFText ? SkSurfaceProps::kUseDistanceFieldFonts_Flag : 0; |
| 395 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
bsalomon | afe3005 | 2015-01-16 07:32:33 -0800 | [diff] [blame] | 396 | target->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(config.ctxType), |
| 397 | SkSurface::kNo_Budgeted, info, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 398 | config.samples, &props)); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 399 | target->gl = gGrFactory->getGLContext(config.ctxType); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 400 | } |
| 401 | #endif |
| 402 | |
| 403 | if (Benchmark::kNonRendering_Backend != config.backend && !target->surface.get()) { |
| 404 | delete target; |
| 405 | return NULL; |
| 406 | } |
| 407 | return target; |
| 408 | } |
| 409 | |
| 410 | // Creates targets for a benchmark and a set of configs. |
| 411 | static void create_targets(SkTDArray<Target*>* targets, Benchmark* b, |
| 412 | const SkTDArray<Config>& configs) { |
| 413 | for (int i = 0; i < configs.count(); ++i) { |
| 414 | if (Target* t = is_enabled(b, configs[i])) { |
| 415 | targets->push(t); |
| 416 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 417 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 421 | #if SK_SUPPORT_GPU |
kkinnunen | 9e61bb7 | 2014-10-09 05:24:15 -0700 | [diff] [blame] | 422 | static void fill_gpu_options(ResultsWriter* log, SkGLContext* ctx) { |
jcgregorio | 05c4560 | 2014-07-17 13:54:36 -0700 | [diff] [blame] | 423 | const GrGLubyte* version; |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 424 | SK_GL_RET(*ctx, version, GetString(GR_GL_VERSION)); |
| 425 | log->configOption("GL_VERSION", (const char*)(version)); |
| 426 | |
| 427 | SK_GL_RET(*ctx, version, GetString(GR_GL_RENDERER)); |
| 428 | log->configOption("GL_RENDERER", (const char*) version); |
| 429 | |
| 430 | SK_GL_RET(*ctx, version, GetString(GR_GL_VENDOR)); |
| 431 | log->configOption("GL_VENDOR", (const char*) version); |
| 432 | |
| 433 | SK_GL_RET(*ctx, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 434 | log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 435 | } |
| 436 | #endif |
| 437 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 438 | class BenchmarkStream { |
| 439 | public: |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 440 | BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 441 | , fGMs(skiagm::GMRegistry::Head()) |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 442 | , fCurrentRecording(0) |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 443 | , fCurrentScale(0) |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 444 | , fCurrentSKP(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 445 | , fCurrentUseMPD(0) |
| 446 | , fCurrentImage(0) |
| 447 | , fCurrentSubsetImage(0) |
| 448 | , fCurrentColorType(0) |
| 449 | , fDivisor(2) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 450 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 451 | if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 452 | fSKPs.push_back() = FLAGS_skps[i]; |
| 453 | } else { |
| 454 | SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 455 | SkString path; |
| 456 | while (it.next(&path)) { |
| 457 | fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
| 458 | } |
| 459 | } |
| 460 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 461 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 462 | if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 463 | &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) { |
| 464 | SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]); |
| 465 | exit(1); |
| 466 | } |
| 467 | |
| 468 | for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 469 | if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 470 | SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]); |
| 471 | exit(1); |
| 472 | } |
| 473 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 474 | |
| 475 | fUseMPDs.push_back() = false; |
| 476 | if (FLAGS_mpd) { |
| 477 | fUseMPDs.push_back() = true; |
| 478 | } |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 479 | |
| 480 | // Prepare the images for decoding |
| 481 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 482 | const char* flag = FLAGS_images[i]; |
| 483 | if (sk_isdir(flag)) { |
| 484 | // If the value passed in is a directory, add all the images |
| 485 | SkOSFile::Iter it(flag); |
| 486 | SkString file; |
| 487 | while (it.next(&file)) { |
| 488 | fImages.push_back() = SkOSPath::Join(flag, file.c_str()); |
| 489 | } |
| 490 | } else if (sk_exists(flag)) { |
| 491 | // Also add the value if it is a single image |
| 492 | fImages.push_back() = flag; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Choose the candidate color types for image decoding |
| 497 | const SkColorType colorTypes[] = |
| 498 | { kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType }; |
| 499 | fColorTypes.push_back_n(SK_ARRAY_COUNT(colorTypes), colorTypes); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 500 | } |
| 501 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 502 | static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
| 503 | // Not strictly necessary, as it will be checked again later, |
| 504 | // but helps to avoid a lot of pointless work if we're going to skip it. |
| 505 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
| 506 | return false; |
| 507 | } |
| 508 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 509 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 510 | if (stream.get() == NULL) { |
| 511 | SkDebugf("Could not read %s.\n", path); |
| 512 | return false; |
| 513 | } |
| 514 | |
mtklein | 57f27bd | 2015-02-09 11:58:41 -0800 | [diff] [blame] | 515 | pic->reset(SkPicture::CreateFromStream(stream.get())); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 516 | if (pic->get() == NULL) { |
| 517 | SkDebugf("Could not read %s as an SkPicture.\n", path); |
| 518 | return false; |
| 519 | } |
| 520 | return true; |
| 521 | } |
| 522 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 523 | Benchmark* next() { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 524 | if (fBenches) { |
| 525 | Benchmark* bench = fBenches->factory()(NULL); |
| 526 | fBenches = fBenches->next(); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 527 | fSourceType = "bench"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 528 | fBenchType = "micro"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 529 | return bench; |
| 530 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 531 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 532 | while (fGMs) { |
| 533 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(NULL)); |
| 534 | fGMs = fGMs->next(); |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 535 | if (gm->runAsBench()) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 536 | fSourceType = "gm"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 537 | fBenchType = "micro"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 538 | return SkNEW_ARGS(GMBench, (gm.detach())); |
| 539 | } |
| 540 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 541 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 542 | // First add all .skps as RecordingBenches. |
| 543 | while (fCurrentRecording < fSKPs.count()) { |
| 544 | const SkString& path = fSKPs[fCurrentRecording++]; |
| 545 | SkAutoTUnref<SkPicture> pic; |
| 546 | if (!ReadPicture(path.c_str(), &pic)) { |
| 547 | continue; |
| 548 | } |
| 549 | SkString name = SkOSPath::Basename(path.c_str()); |
| 550 | fSourceType = "skp"; |
| 551 | fBenchType = "recording"; |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 552 | fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic)); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 553 | fSKPOps = pic->approximateOpCount(); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 554 | return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bbh)); |
| 555 | } |
| 556 | |
| 557 | // Then once each for each scale as SKPBenches (playback). |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 558 | while (fCurrentScale < fScales.count()) { |
| 559 | while (fCurrentSKP < fSKPs.count()) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 560 | const SkString& path = fSKPs[fCurrentSKP]; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 561 | SkAutoTUnref<SkPicture> pic; |
| 562 | if (!ReadPicture(path.c_str(), &pic)) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 563 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 564 | continue; |
| 565 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 566 | |
| 567 | while (fCurrentUseMPD < fUseMPDs.count()) { |
| 568 | if (FLAGS_bbh) { |
| 569 | // The SKP we read off disk doesn't have a BBH. Re-record so it grows one. |
| 570 | SkRTreeFactory factory; |
| 571 | SkPictureRecorder recorder; |
| 572 | static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; |
| 573 | pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 574 | pic->cullRect().height(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 575 | &factory, |
robertphillips | e451c4d | 2014-12-09 10:28:00 -0800 | [diff] [blame] | 576 | fUseMPDs[fCurrentUseMPD] ? kFlags : 0)); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 577 | pic.reset(recorder.endRecording()); |
| 578 | } |
| 579 | SkString name = SkOSPath::Basename(path.c_str()); |
| 580 | fSourceType = "skp"; |
| 581 | fBenchType = "playback"; |
| 582 | return SkNEW_ARGS(SKPBench, |
| 583 | (name.c_str(), pic.get(), fClip, |
| 584 | fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++])); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 585 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 586 | fCurrentUseMPD = 0; |
| 587 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 588 | } |
| 589 | fCurrentSKP = 0; |
| 590 | fCurrentScale++; |
| 591 | } |
| 592 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 593 | // Run the DecodingBenches |
| 594 | while (fCurrentImage < fImages.count()) { |
| 595 | while (fCurrentColorType < fColorTypes.count()) { |
| 596 | const SkString& path = fImages[fCurrentImage]; |
| 597 | SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 598 | fCurrentColorType++; |
| 599 | // Check if the image decodes before creating the benchmark |
| 600 | SkBitmap bitmap; |
| 601 | if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
| 602 | colorType, SkImageDecoder::kDecodePixels_Mode)) { |
| 603 | return new DecodingBench(path, colorType); |
| 604 | } |
| 605 | } |
| 606 | fCurrentColorType = 0; |
| 607 | fCurrentImage++; |
| 608 | } |
| 609 | |
| 610 | // Run the DecodingSubsetBenches |
| 611 | while (fCurrentSubsetImage < fImages.count()) { |
| 612 | while (fCurrentColorType < fColorTypes.count()) { |
| 613 | const SkString& path = fImages[fCurrentSubsetImage]; |
| 614 | SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 615 | fCurrentColorType++; |
| 616 | // Check if the image decodes before creating the benchmark |
| 617 | SkAutoTUnref<SkData> encoded( |
| 618 | SkData::NewFromFileName(path.c_str())); |
| 619 | SkAutoTDelete<SkMemoryStream> stream( |
| 620 | new SkMemoryStream(encoded)); |
| 621 | SkAutoTDelete<SkImageDecoder> |
| 622 | decoder(SkImageDecoder::Factory(stream.get())); |
| 623 | if (!decoder) { |
| 624 | SkDebugf("Cannot find decoder for %s\n", path.c_str()); |
| 625 | } else { |
| 626 | stream->rewind(); |
| 627 | int w, h; |
| 628 | bool success; |
| 629 | if (!decoder->buildTileIndex(stream.detach(), &w, &h) |
| 630 | || w*h == 1) { |
| 631 | // This is not an error, but in this case we still |
| 632 | // do not want to run the benchmark. |
| 633 | success = false; |
| 634 | } else if (fDivisor > w || fDivisor > h) { |
| 635 | SkDebugf("Divisor %d is too big for %s %dx%d\n", |
| 636 | fDivisor, path.c_str(), w, h); |
| 637 | success = false; |
| 638 | } else { |
| 639 | const int sW = w / fDivisor; |
| 640 | const int sH = h / fDivisor; |
| 641 | SkBitmap bitmap; |
| 642 | success = true; |
| 643 | for (int y = 0; y < h; y += sH) { |
| 644 | for (int x = 0; x < w; x += sW) { |
| 645 | SkIRect rect = SkIRect::MakeXYWH(x, y, sW, sH); |
| 646 | success &= decoder->decodeSubset(&bitmap, rect, |
| 647 | colorType); |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | // Create the benchmark if successful |
| 652 | if (success) { |
| 653 | return new DecodingSubsetBench(path, colorType, |
| 654 | fDivisor); |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | fCurrentColorType = 0; |
| 659 | fCurrentSubsetImage++; |
| 660 | } |
| 661 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 662 | return NULL; |
| 663 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 664 | |
| 665 | void fillCurrentOptions(ResultsWriter* log) const { |
| 666 | log->configOption("source_type", fSourceType); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 667 | log->configOption("bench_type", fBenchType); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 668 | if (0 == strcmp(fSourceType, "skp")) { |
| 669 | log->configOption("clip", |
| 670 | SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 671 | fClip.fRight, fClip.fBottom).c_str()); |
| 672 | log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str()); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 673 | if (fCurrentUseMPD > 0) { |
| 674 | SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
| 675 | log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false"); |
| 676 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 677 | } |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 678 | if (0 == strcmp(fBenchType, "recording")) { |
| 679 | log->metric("bytes", fSKPBytes); |
| 680 | log->metric("ops", fSKPOps); |
| 681 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 682 | } |
| 683 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 684 | private: |
| 685 | const BenchRegistry* fBenches; |
| 686 | const skiagm::GMRegistry* fGMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 687 | SkIRect fClip; |
| 688 | SkTArray<SkScalar> fScales; |
| 689 | SkTArray<SkString> fSKPs; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 690 | SkTArray<bool> fUseMPDs; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 691 | SkTArray<SkString> fImages; |
| 692 | SkTArray<SkColorType> fColorTypes; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 693 | |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 694 | double fSKPBytes, fSKPOps; |
| 695 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 696 | const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 697 | const char* fBenchType; // How we bench it: micro, recording, playback, ... |
| 698 | int fCurrentRecording; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 699 | int fCurrentScale; |
| 700 | int fCurrentSKP; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 701 | int fCurrentUseMPD; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 702 | int fCurrentImage; |
| 703 | int fCurrentSubsetImage; |
| 704 | int fCurrentColorType; |
| 705 | const int fDivisor; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 706 | }; |
| 707 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 708 | int nanobench_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 709 | int nanobench_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 710 | SetupCrashHandler(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 711 | SkAutoGraphics ag; |
mtklein | 4f10844 | 2014-12-03 13:07:39 -0800 | [diff] [blame] | 712 | SkTaskGroup::Enabler enabled; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 713 | |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 714 | #if SK_SUPPORT_GPU |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 715 | GrContext::Options grContextOpts; |
| 716 | grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; |
| 717 | gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts))); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 718 | #endif |
| 719 | |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 720 | if (FLAGS_veryVerbose) { |
| 721 | FLAGS_verbose = true; |
| 722 | } |
| 723 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 724 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 725 | FLAGS_samples = 1; |
| 726 | FLAGS_gpuFrameLag = 0; |
| 727 | } |
| 728 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 729 | if (!FLAGS_writePath.isEmpty()) { |
| 730 | SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
| 731 | if (!sk_mkdir(FLAGS_writePath[0])) { |
| 732 | SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]); |
| 733 | FLAGS_writePath.set(0, NULL); |
| 734 | } |
| 735 | } |
| 736 | |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 737 | SkAutoTDelete<ResultsWriter> log(SkNEW(ResultsWriter)); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 738 | if (!FLAGS_outResultsFile.isEmpty()) { |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 739 | log.reset(SkNEW(NanoJSONResultsWriter(FLAGS_outResultsFile[0]))); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 740 | } |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 741 | |
| 742 | if (1 == FLAGS_properties.count() % 2) { |
| 743 | SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n"); |
| 744 | return 1; |
| 745 | } |
| 746 | for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
| 747 | log->property(FLAGS_properties[i-1], FLAGS_properties[i]); |
| 748 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 749 | |
| 750 | if (1 == FLAGS_key.count() % 2) { |
| 751 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 752 | return 1; |
| 753 | } |
| 754 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 755 | log->key(FLAGS_key[i-1], FLAGS_key[i]); |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame] | 756 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 757 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 758 | const double overhead = estimate_timer_overhead(); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 759 | SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); |
Mike Klein | 9129477 | 2014-07-16 19:59:32 -0400 | [diff] [blame] | 760 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 761 | SkAutoTMalloc<double> samples(FLAGS_samples); |
| 762 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 763 | if (kAutoTuneLoops != FLAGS_loops) { |
| 764 | SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n"); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 765 | } else if (FLAGS_verbose) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 766 | // No header. |
| 767 | } else if (FLAGS_quiet) { |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 768 | SkDebugf("median\tbench\tconfig\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 769 | } else { |
qiankun.miao | 8247ec3 | 2014-09-09 19:24:36 -0700 | [diff] [blame] | 770 | SkDebugf("maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |
| 771 | FLAGS_samples, "samples"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 772 | } |
| 773 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 774 | SkTDArray<Config> configs; |
| 775 | create_configs(&configs); |
| 776 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 777 | int runs = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 778 | BenchmarkStream benchStream; |
| 779 | while (Benchmark* b = benchStream.next()) { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 780 | SkAutoTDelete<Benchmark> bench(b); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 781 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 782 | continue; |
| 783 | } |
| 784 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 785 | SkTDArray<Target*> targets; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 786 | create_targets(&targets, bench.get(), configs); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 787 | |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 788 | if (!targets.isEmpty()) { |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 789 | log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 790 | bench->preDraw(); |
| 791 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 792 | for (int j = 0; j < targets.count(); j++) { |
| 793 | SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface->getCanvas() : NULL; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 794 | const char* config = targets[j]->config.name; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 795 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 796 | #if SK_SUPPORT_GPU |
| 797 | if (Benchmark::kGPU_Backend == targets[j]->config.backend) { |
| 798 | setup_gl(targets[j]->gl); |
| 799 | } |
| 800 | #endif |
| 801 | |
| 802 | bench->perCanvasPreDraw(canvas); |
| 803 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 804 | const int loops = |
| 805 | #if SK_SUPPORT_GPU |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 806 | Benchmark::kGPU_Backend == targets[j]->config.backend |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 807 | ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) |
| 808 | : |
| 809 | #endif |
| 810 | cpu_bench( overhead, bench.get(), canvas, samples.get()); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 811 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 812 | bench->perCanvasPostDraw(canvas); |
| 813 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 814 | if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 815 | SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 816 | pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName()); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 817 | pngFilename.append(".png"); |
| 818 | write_canvas_png(canvas, pngFilename); |
| 819 | } |
| 820 | |
| 821 | if (kFailedLoops == loops) { |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 822 | // Can't be timed. A warning note has already been printed. |
Mike Klein | e363136 | 2014-07-15 17:56:37 -0400 | [diff] [blame] | 823 | continue; |
| 824 | } |
| 825 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 826 | Stats stats(samples.get(), FLAGS_samples); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 827 | log->config(config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 828 | log->configOption("name", bench->getName()); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 829 | benchStream.fillCurrentOptions(log.get()); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 830 | #if SK_SUPPORT_GPU |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 831 | if (Benchmark::kGPU_Backend == targets[j]->config.backend) { |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 832 | fill_gpu_options(log.get(), targets[j]->gl); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 833 | } |
| 834 | #endif |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 835 | log->metric("min_ms", stats.min); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 836 | if (runs++ % FLAGS_flushEvery == 0) { |
| 837 | log->flush(); |
| 838 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 839 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 840 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 841 | if (targets.count() == 1) { |
| 842 | config = ""; // Only print the config if we run the same bench on more than one. |
| 843 | } |
mtklein | 53d2562 | 2014-09-18 07:39:42 -0700 | [diff] [blame] | 844 | SkDebugf("%4dM\t%s\t%s\n" |
| 845 | , sk_tools::getMaxResidentSetSizeMB() |
| 846 | , bench->getUniqueName() |
| 847 | , config); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 848 | } else if (FLAGS_verbose) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 849 | for (int i = 0; i < FLAGS_samples; i++) { |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 850 | SkDebugf("%s ", HUMANIZE(samples[i])); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 851 | } |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 852 | SkDebugf("%s\n", bench->getUniqueName()); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 853 | } else if (FLAGS_quiet) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 854 | if (targets.count() == 1) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 855 | config = ""; // Only print the config if we run the same bench on more than one. |
| 856 | } |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 857 | SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 858 | } else { |
| 859 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 860 | SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" |
| 861 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 862 | , loops |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 863 | , HUMANIZE(stats.min) |
| 864 | , HUMANIZE(stats.median) |
| 865 | , HUMANIZE(stats.mean) |
| 866 | , HUMANIZE(stats.max) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 867 | , stddev_percent |
mtklein | 5d9d10e | 2014-07-11 11:57:07 -0700 | [diff] [blame] | 868 | , stats.plot.c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 869 | , config |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 870 | , bench->getUniqueName() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 871 | ); |
| 872 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 873 | #if SK_SUPPORT_GPU |
| 874 | if (FLAGS_gpuStats && |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 875 | Benchmark::kGPU_Backend == targets[j]->config.backend) { |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 876 | gGrFactory->get(targets[j]->config.ctxType)->printCacheStats(); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 877 | gGrFactory->get(targets[j]->config.ctxType)->printGpuStats(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 878 | } |
| 879 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 880 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 881 | targets.deleteAll(); |
Mike Klein | 3944a1d | 2014-07-15 13:40:19 -0400 | [diff] [blame] | 882 | |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 883 | #if SK_SUPPORT_GPU |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 884 | if (FLAGS_abandonGpuContext) { |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 885 | gGrFactory->abandonContexts(); |
bsalomon | 2354f84 | 2014-07-28 13:48:36 -0700 | [diff] [blame] | 886 | } |
| 887 | if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 888 | gGrFactory->destroyContexts(); |
Mike Klein | 3944a1d | 2014-07-15 13:40:19 -0400 | [diff] [blame] | 889 | } |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 890 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 891 | } |
| 892 | |
mtklein | e109145 | 2014-12-04 10:47:02 -0800 | [diff] [blame] | 893 | log->bench("memory_usage", 0,0); |
| 894 | log->config("meta"); |
| 895 | log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB()); |
| 896 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 897 | return 0; |
| 898 | } |
| 899 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 900 | #if !defined SK_BUILD_FOR_IOS |
| 901 | int main(int argc, char** argv) { |
| 902 | SkCommandLineFlags::Parse(argc, argv); |
| 903 | return nanobench_main(); |
| 904 | } |
| 905 | #endif |