reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 8 | #include "BenchLogger.h" |
mtklein | 9ac68ee | 2014-06-20 11:29:20 -0700 | [diff] [blame] | 9 | #include "Timer.h" |
scroggo@google.com | 4a26d9d | 2012-11-07 18:01:46 +0000 | [diff] [blame] | 10 | #include "CopyTilesRenderer.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 11 | #include "CrashHandler.h" |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 12 | #include "LazyDecodeBitmap.h" |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 13 | #include "PictureBenchmark.h" |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 14 | #include "PictureRenderingFlags.h" |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 15 | #include "PictureResultsWriter.h" |
scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 16 | #include "SkCommandLineFlags.h" |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 17 | #include "SkData.h" |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 18 | #include "SkDiscardableMemoryPool.h" |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 19 | #include "SkGraphics.h" |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 20 | #include "SkImageDecoder.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 21 | #include "SkMath.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 22 | #include "SkOSFile.h" |
| 23 | #include "SkPicture.h" |
| 24 | #include "SkStream.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 25 | #include "picture_utils.h" |
| 26 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 27 | BenchLogger gLogger; |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 28 | PictureResultsLoggerWriter gLogWriter(&gLogger); |
| 29 | PictureResultsMultiWriter gWriter; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 30 | |
| 31 | // Flags used by this file, in alphabetical order. |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 32 | DEFINE_bool(countRAM, false, "Count the RAM used for bitmap pixels in each skp file"); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 33 | DECLARE_bool(deferImageDecoding); |
| 34 | DEFINE_string(filter, "", |
| 35 | "type:flag : Enable canvas filtering to disable a paint flag, " |
| 36 | "use no blur or low quality blur, or use no hinting or " |
| 37 | "slight hinting. For all flags except AAClip, specify the " |
| 38 | "type of primitive to effect, or choose all. for AAClip " |
| 39 | "alone, the filter affects all clips independent of type. " |
| 40 | "Specific flags are listed above."); |
| 41 | DEFINE_string(logFile, "", "Destination for writing log output, in addition to stdout."); |
| 42 | DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean."); |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 43 | DEFINE_string(jsonLog, "", "Destination for writing JSON data."); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 44 | DEFINE_bool(min, false, "Print the minimum times (instead of average)."); |
scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 45 | DECLARE_string(readPath); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 46 | DEFINE_int32(repeat, 1, "Set the number of times to repeat each test."); |
| 47 | DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than " |
| 48 | "times for drawing the whole page. Requires tiled rendering."); |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 49 | DEFINE_bool(purgeDecodedTex, false, "Purge decoded and GPU-uploaded textures " |
| 50 | "after each iteration."); |
scroggo@google.com | 65e508d | 2013-08-02 16:09:10 +0000 | [diff] [blame] | 51 | DEFINE_string(timers, "c", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time" |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 52 | " for each picture."); |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 53 | DEFINE_bool(trackDeferredCaching, false, "Only meaningful with --deferImageDecoding and " |
commit-bot@chromium.org | cf2f008 | 2014-04-04 16:43:38 +0000 | [diff] [blame] | 54 | "SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using " |
| 55 | "deferred image decoding."); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 56 | |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 57 | #if GR_GPU_STATS |
| 58 | DEFINE_bool(gpuStats, false, "Only meaningful with gpu configurations. " |
| 59 | "Report some GPU call statistics."); |
| 60 | #endif |
| 61 | |
robertphillips | 78c7127 | 2014-10-09 04:59:19 -0700 | [diff] [blame] | 62 | DEFINE_bool(mpd, false, "If true, use MultiPictureDraw to render."); |
commit-bot@chromium.org | c873329 | 2014-04-11 15:54:14 +0000 | [diff] [blame] | 63 | |
kelvinly | 4d1a364 | 2014-06-26 11:26:40 -0700 | [diff] [blame] | 64 | // Buildbot-specific parameters |
| 65 | DEFINE_string(builderName, "", "Name of the builder this is running on."); |
| 66 | DEFINE_int32(buildNumber, -1, "Build number of the build this test is running on"); |
| 67 | DEFINE_int32(timestamp, 0, "Timestamp of the revision of Skia being tested."); |
| 68 | DEFINE_string(gitHash, "", "Commit hash of the revision of Skia being run."); |
| 69 | DEFINE_int32(gitNumber, -1, "Git number of the revision of Skia being run."); |
| 70 | |
| 71 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 72 | static char const * const gFilterTypes[] = { |
| 73 | "paint", |
| 74 | "point", |
| 75 | "line", |
| 76 | "bitmap", |
| 77 | "rect", |
jvanverth@google.com | d3c208c | 2013-01-22 13:54:52 +0000 | [diff] [blame] | 78 | "oval", |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 79 | "path", |
| 80 | "text", |
| 81 | "all", |
| 82 | }; |
| 83 | |
| 84 | static const size_t kFilterTypesCount = sizeof(gFilterTypes) / sizeof(gFilterTypes[0]); |
| 85 | |
| 86 | static char const * const gFilterFlags[] = { |
| 87 | "antiAlias", |
| 88 | "filterBitmap", |
| 89 | "dither", |
| 90 | "underlineText", |
| 91 | "strikeThruText", |
| 92 | "fakeBoldText", |
| 93 | "linearText", |
| 94 | "subpixelText", |
| 95 | "devKernText", |
| 96 | "LCDRenderText", |
| 97 | "embeddedBitmapText", |
| 98 | "autoHinting", |
| 99 | "verticalText", |
| 100 | "genA8FromLCD", |
| 101 | "blur", |
| 102 | "hinting", |
| 103 | "slightHinting", |
caryclark@google.com | e3e940c | 2012-11-07 16:42:17 +0000 | [diff] [blame] | 104 | "AAClip", |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | static const size_t kFilterFlagsCount = sizeof(gFilterFlags) / sizeof(gFilterFlags[0]); |
| 108 | |
| 109 | static SkString filtersName(sk_tools::PictureRenderer::DrawFilterFlags* drawFilters) { |
| 110 | int all = drawFilters[0]; |
| 111 | size_t tIndex; |
| 112 | for (tIndex = 1; tIndex < SkDrawFilter::kTypeCount; ++tIndex) { |
| 113 | all &= drawFilters[tIndex]; |
| 114 | } |
| 115 | SkString result; |
| 116 | for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) { |
| 117 | SkString types; |
| 118 | if (all & (1 << fIndex)) { |
| 119 | types = gFilterTypes[SkDrawFilter::kTypeCount]; |
| 120 | } else { |
| 121 | for (tIndex = 0; tIndex < SkDrawFilter::kTypeCount; ++tIndex) { |
| 122 | if (drawFilters[tIndex] & (1 << fIndex)) { |
| 123 | types += gFilterTypes[tIndex]; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | if (!types.size()) { |
| 128 | continue; |
| 129 | } |
| 130 | result += "_"; |
| 131 | result += types; |
| 132 | result += "."; |
| 133 | result += gFilterFlags[fIndex]; |
| 134 | } |
| 135 | return result; |
| 136 | } |
| 137 | |
| 138 | static SkString filterTypesUsage() { |
| 139 | SkString result; |
| 140 | for (size_t index = 0; index < kFilterTypesCount; ++index) { |
| 141 | result += gFilterTypes[index]; |
| 142 | if (index < kFilterTypesCount - 1) { |
| 143 | result += " | "; |
| 144 | } |
| 145 | } |
| 146 | return result; |
| 147 | } |
| 148 | |
| 149 | static SkString filterFlagsUsage() { |
| 150 | SkString result; |
| 151 | size_t len = 0; |
| 152 | for (size_t index = 0; index < kFilterFlagsCount; ++index) { |
| 153 | result += gFilterFlags[index]; |
| 154 | if (result.size() - len >= 72) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 155 | result += "\n\t\t"; |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 156 | len = result.size(); |
| 157 | } |
| 158 | if (index < kFilterFlagsCount - 1) { |
| 159 | result += " | "; |
| 160 | } |
| 161 | } |
| 162 | return result; |
| 163 | } |
| 164 | |
commit-bot@chromium.org | cf2f008 | 2014-04-04 16:43:38 +0000 | [diff] [blame] | 165 | #if SK_LAZY_CACHE_STATS |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 166 | static int32_t gTotalCacheHits; |
| 167 | static int32_t gTotalCacheMisses; |
| 168 | #endif |
| 169 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 170 | static bool run_single_benchmark(const SkString& inputPath, |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 171 | sk_tools::PictureBenchmark& benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 172 | SkFILEStream inputStream; |
| 173 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 174 | inputStream.setPath(inputPath.c_str()); |
| 175 | if (!inputStream.isValid()) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 176 | SkString err; |
| 177 | err.printf("Could not open file %s\n", inputPath.c_str()); |
| 178 | gLogger.logError(err); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 179 | return false; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 180 | } |
| 181 | |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 182 | SkDiscardableMemoryPool* pool = SkGetGlobalDiscardableMemoryPool(); |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 183 | // Since the old picture has been deleted, all pixels should be cleared. |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 184 | SkASSERT(pool->getRAMUsed() == 0); |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 185 | if (FLAGS_countRAM) { |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 186 | pool->setRAMBudget(SK_MaxU32); |
| 187 | // Set the limit to max, so all pixels will be kept |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 188 | } |
| 189 | |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 190 | SkPicture::InstallPixelRefProc proc; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 191 | if (FLAGS_deferImageDecoding) { |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 192 | proc = &sk_tools::LazyDecodeBitmap; |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 193 | } else { |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 194 | proc = &SkImageDecoder::DecodeMemory; |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 195 | } |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 196 | SkAutoTUnref<SkPicture> picture(SkPicture::CreateFromStream(&inputStream, proc)); |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 197 | |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 198 | if (NULL == picture.get()) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 199 | SkString err; |
| 200 | err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 201 | gLogger.logError(err); |
| 202 | return false; |
| 203 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 204 | |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 205 | SkString filename = SkOSPath::Basename(inputPath.c_str()); |
keyar@chromium.org | db9a5fb | 2012-08-21 17:57:59 +0000 | [diff] [blame] | 206 | |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 207 | gWriter.bench(filename.c_str(), |
| 208 | SkScalarCeilToInt(picture->cullRect().width()), |
| 209 | SkScalarCeilToInt(picture->cullRect().height())); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 210 | |
robertphillips | 78c7127 | 2014-10-09 04:59:19 -0700 | [diff] [blame] | 211 | benchmark.run(picture, FLAGS_mpd); |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 212 | |
commit-bot@chromium.org | cf2f008 | 2014-04-04 16:43:38 +0000 | [diff] [blame] | 213 | #if SK_LAZY_CACHE_STATS |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 214 | if (FLAGS_trackDeferredCaching) { |
commit-bot@chromium.org | cf2f008 | 2014-04-04 16:43:38 +0000 | [diff] [blame] | 215 | int cacheHits = pool->getCacheHits(); |
| 216 | int cacheMisses = pool->getCacheMisses(); |
| 217 | pool->resetCacheHitsAndMisses(); |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 218 | SkString hitString; |
| 219 | hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses)); |
| 220 | gLogger.logProgress(hitString); |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 221 | gTotalCacheHits += cacheHits; |
| 222 | gTotalCacheMisses += cacheMisses; |
| 223 | } |
| 224 | #endif |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 225 | if (FLAGS_countRAM) { |
| 226 | SkString ramCount("RAM used for bitmaps: "); |
halcanary@google.com | 2c7c7ee | 2013-12-05 18:31:42 +0000 | [diff] [blame] | 227 | size_t bytes = pool->getRAMUsed(); |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 228 | if (bytes > 1024) { |
| 229 | size_t kb = bytes / 1024; |
| 230 | if (kb > 1024) { |
| 231 | size_t mb = kb / 1024; |
| 232 | ramCount.appendf("%zi MB\n", mb); |
| 233 | } else { |
| 234 | ramCount.appendf("%zi KB\n", kb); |
| 235 | } |
| 236 | } else { |
| 237 | ramCount.appendf("%zi bytes\n", bytes); |
| 238 | } |
| 239 | gLogger.logProgress(ramCount); |
| 240 | } |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 241 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 242 | return true; |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 243 | } |
| 244 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 245 | static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) { |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 246 | sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount]; |
| 247 | sk_bzero(drawFilters, sizeof(drawFilters)); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 248 | |
| 249 | if (FLAGS_filter.count() > 0) { |
| 250 | const char* filters = FLAGS_filter[0]; |
| 251 | const char* colon = strchr(filters, ':'); |
| 252 | if (colon) { |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 253 | int32_t type = -1; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 254 | size_t typeLen = colon - filters; |
| 255 | for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) { |
| 256 | if (typeLen == strlen(gFilterTypes[tIndex]) |
| 257 | && !strncmp(filters, gFilterTypes[tIndex], typeLen)) { |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 258 | type = SkToS32(tIndex); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 259 | break; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 260 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 261 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 262 | if (type < 0) { |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 263 | SkString err; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 264 | err.printf("Unknown type for --filter %s\n", filters); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 265 | gLogger.logError(err); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 266 | exit(-1); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 267 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 268 | int flag = -1; |
| 269 | size_t flagLen = strlen(filters) - typeLen - 1; |
| 270 | for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) { |
| 271 | if (flagLen == strlen(gFilterFlags[fIndex]) |
| 272 | && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) { |
| 273 | flag = 1 << fIndex; |
| 274 | break; |
| 275 | } |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 276 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 277 | if (flag < 0) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 278 | SkString err; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 279 | err.printf("Unknown flag for --filter %s\n", filters); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 280 | gLogger.logError(err); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 281 | exit(-1); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 282 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 283 | for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) { |
| 284 | if (type != SkDrawFilter::kTypeCount && index != type) { |
| 285 | continue; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 286 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 287 | drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags) |
| 288 | (drawFilters[index] | flag); |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 289 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 290 | } else { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 291 | SkString err; |
| 292 | err.printf("Unknown arg for --filter %s : missing colon\n", filters); |
| 293 | gLogger.logError(err); |
| 294 | exit(-1); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 298 | if (FLAGS_timers.count() > 0) { |
| 299 | size_t index = 0; |
| 300 | bool timerWall = false; |
| 301 | bool truncatedTimerWall = false; |
| 302 | bool timerCpu = false; |
| 303 | bool truncatedTimerCpu = false; |
| 304 | bool timerGpu = false; |
| 305 | while (index < strlen(FLAGS_timers[0])) { |
| 306 | switch (FLAGS_timers[0][index]) { |
| 307 | case 'w': |
| 308 | timerWall = true; |
| 309 | break; |
| 310 | case 'c': |
| 311 | timerCpu = true; |
| 312 | break; |
| 313 | case 'W': |
| 314 | truncatedTimerWall = true; |
| 315 | break; |
| 316 | case 'C': |
| 317 | truncatedTimerCpu = true; |
| 318 | break; |
| 319 | case 'g': |
| 320 | timerGpu = true; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 321 | break; |
| 322 | default: |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 323 | SkDebugf("mystery character\n"); |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 324 | break; |
| 325 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 326 | index++; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 327 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 328 | benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu, |
| 329 | timerGpu); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 330 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 331 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 332 | SkString errorString; |
| 333 | SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, |
| 334 | kBench_PictureTool)); |
| 335 | |
| 336 | if (errorString.size() > 0) { |
| 337 | gLogger.logError(errorString); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 338 | } |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 339 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 340 | if (NULL == renderer.get()) { |
| 341 | exit(-1); |
| 342 | } |
| 343 | |
| 344 | if (FLAGS_timeIndividualTiles) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 345 | sk_tools::TiledPictureRenderer* tiledRenderer = renderer->getTiledRenderer(); |
| 346 | if (NULL == tiledRenderer) { |
| 347 | gLogger.logError("--timeIndividualTiles requires tiled rendering.\n"); |
| 348 | exit(-1); |
| 349 | } |
| 350 | if (!tiledRenderer->supportsTimingIndividualTiles()) { |
| 351 | gLogger.logError("This renderer does not support --timeIndividualTiles.\n"); |
| 352 | exit(-1); |
| 353 | } |
| 354 | benchmark->setTimeIndividualTiles(true); |
| 355 | } |
| 356 | |
robertphillips@google.com | 94d8f1e | 2013-12-18 17:25:33 +0000 | [diff] [blame] | 357 | benchmark->setPurgeDecodedTex(FLAGS_purgeDecodedTex); |
| 358 | |
scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 359 | if (FLAGS_readPath.count() < 1) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 360 | gLogger.logError(".skp files or directories are required.\n"); |
| 361 | exit(-1); |
| 362 | } |
| 363 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 364 | renderer->setDrawFilters(drawFilters, filtersName(drawFilters)); |
commit-bot@chromium.org | 55fd612 | 2013-07-31 20:00:56 +0000 | [diff] [blame] | 365 | if (FLAGS_logPerIter) { |
| 366 | benchmark->setTimerResultType(TimerData::kPerIter_Result); |
| 367 | } else if (FLAGS_min) { |
| 368 | benchmark->setTimerResultType(TimerData::kMin_Result); |
| 369 | } else { |
| 370 | benchmark->setTimerResultType(TimerData::kAvg_Result); |
| 371 | } |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 372 | benchmark->setRenderer(renderer); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 373 | benchmark->setRepeats(FLAGS_repeat); |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 374 | benchmark->setWriter(&gWriter); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 375 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 376 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 377 | static int process_input(const char* input, |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 378 | sk_tools::PictureBenchmark& benchmark) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 379 | SkString inputAsSkString(input); |
| 380 | SkOSFile::Iter iter(input, "skp"); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 381 | SkString inputFilename; |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 382 | int failures = 0; |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 383 | if (iter.next(&inputFilename)) { |
| 384 | do { |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 385 | SkString inputPath = SkOSPath::Join(input, inputFilename.c_str()); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 386 | if (!run_single_benchmark(inputPath, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 387 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 388 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 389 | } while(iter.next(&inputFilename)); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 390 | } else if (SkStrEndsWith(input, ".skp")) { |
| 391 | if (!run_single_benchmark(inputAsSkString, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 392 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 393 | } |
| 394 | } else { |
| 395 | SkString warning; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 396 | warning.printf("Warning: skipping %s\n", input); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 397 | gLogger.logError(warning); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 398 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 399 | return failures; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 400 | } |
| 401 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 402 | int tool_main(int argc, char** argv); |
| 403 | int tool_main(int argc, char** argv) { |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 404 | SetupCrashHandler(); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 405 | SkString usage; |
| 406 | usage.printf("Time drawing .skp files.\n" |
| 407 | "\tPossible arguments for --filter: [%s]\n\t\t[%s]", |
| 408 | filterTypesUsage().c_str(), filterFlagsUsage().c_str()); |
scroggo@google.com | d9ba9a0 | 2013-03-21 19:43:15 +0000 | [diff] [blame] | 409 | SkCommandLineFlags::SetUsage(usage.c_str()); |
| 410 | SkCommandLineFlags::Parse(argc, argv); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 411 | |
| 412 | if (FLAGS_repeat < 1) { |
| 413 | SkString error; |
| 414 | error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat); |
| 415 | gLogger.logError(error); |
| 416 | exit(-1); |
| 417 | } |
| 418 | |
| 419 | if (FLAGS_logFile.count() == 1) { |
| 420 | if (!gLogger.SetLogFile(FLAGS_logFile[0])) { |
| 421 | SkString str; |
| 422 | str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]); |
| 423 | gLogger.logError(str); |
| 424 | // TODO(borenet): We're disabling this for now, due to |
| 425 | // write-protected Android devices. The very short-term |
| 426 | // solution is to ignore the fact that we have no log file. |
| 427 | //exit(-1); |
| 428 | } |
| 429 | } |
| 430 | |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 431 | SkAutoTDelete<PictureJSONResultsWriter> jsonWriter; |
| 432 | if (FLAGS_jsonLog.count() == 1) { |
kelvinly | 4d1a364 | 2014-06-26 11:26:40 -0700 | [diff] [blame] | 433 | SkASSERT(FLAGS_builderName.count() == 1 && FLAGS_gitHash.count() == 1); |
| 434 | jsonWriter.reset(SkNEW(PictureJSONResultsWriter( |
| 435 | FLAGS_jsonLog[0], |
| 436 | FLAGS_builderName[0], |
| 437 | FLAGS_buildNumber, |
| 438 | FLAGS_timestamp, |
| 439 | FLAGS_gitHash[0], |
| 440 | FLAGS_gitNumber))); |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 441 | gWriter.add(jsonWriter.get()); |
| 442 | } |
| 443 | |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 444 | gWriter.add(&gLogWriter); |
| 445 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 446 | |
bsalomon@google.com | 4e23068 | 2013-01-15 20:37:04 +0000 | [diff] [blame] | 447 | #if SK_ENABLE_INST_COUNT |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 448 | gPrintInstCount = true; |
| 449 | #endif |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 450 | SkAutoGraphics ag; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 451 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 452 | sk_tools::PictureBenchmark benchmark; |
| 453 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 454 | setup_benchmark(&benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 455 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 456 | int failures = 0; |
scroggo@google.com | 604e0c2 | 2013-04-09 21:25:46 +0000 | [diff] [blame] | 457 | for (int i = 0; i < FLAGS_readPath.count(); ++i) { |
| 458 | failures += process_input(FLAGS_readPath[i], benchmark); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | if (failures != 0) { |
| 462 | SkString err; |
| 463 | err.printf("Failed to run %i benchmarks.\n", failures); |
| 464 | gLogger.logError(err); |
| 465 | return 1; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 466 | } |
commit-bot@chromium.org | cf2f008 | 2014-04-04 16:43:38 +0000 | [diff] [blame] | 467 | #if SK_LAZY_CACHE_STATS |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 468 | if (FLAGS_trackDeferredCaching) { |
| 469 | SkDebugf("Total cache hit rate: %f\n", |
| 470 | (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses)); |
| 471 | } |
| 472 | #endif |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 473 | |
bsalomon | 24234fe | 2014-10-24 09:34:41 -0700 | [diff] [blame] | 474 | #if GR_GPU_STATS && SK_SUPPORT_GPU |
robertphillips | 754f4e9 | 2014-09-18 13:52:08 -0700 | [diff] [blame] | 475 | if (FLAGS_gpuStats && benchmark.renderer()->isUsingGpuDevice()) { |
| 476 | GrContext* ctx = benchmark.renderer()->getGrContext(); |
| 477 | SkDebugf("RenderTarget Binds: %d\n", ctx->gpuStats()->renderTargetBinds()); |
| 478 | SkDebugf("Shader Compilations: %d\n", ctx->gpuStats()->shaderCompilations()); |
| 479 | } |
| 480 | #endif |
| 481 | |
commit-bot@chromium.org | 37c772a | 2014-05-29 17:10:24 +0000 | [diff] [blame] | 482 | gWriter.end(); |
caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 483 | return 0; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 484 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 485 | |
| 486 | #if !defined SK_BUILD_FOR_IOS |
| 487 | int main(int argc, char * const argv[]) { |
| 488 | return tool_main(argc, (char**) argv); |
| 489 | } |
| 490 | #endif |