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