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