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