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