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 | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 13 | #include "SkBitmapFactory.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 14 | #include "SkCanvas.h" |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 15 | #include "SkFlags.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" |
| 22 | #include "SkTArray.h" |
| 23 | #include "picture_utils.h" |
| 24 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 25 | |
| 26 | SkBenchLogger gLogger; |
| 27 | |
| 28 | // Flags used by this file, in alphabetical order. |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 29 | 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] | 30 | DECLARE_bool(deferImageDecoding); |
| 31 | DEFINE_string(filter, "", |
| 32 | "type:flag : Enable canvas filtering to disable a paint flag, " |
| 33 | "use no blur or low quality blur, or use no hinting or " |
| 34 | "slight hinting. For all flags except AAClip, specify the " |
| 35 | "type of primitive to effect, or choose all. for AAClip " |
| 36 | "alone, the filter affects all clips independent of type. " |
| 37 | "Specific flags are listed above."); |
| 38 | DEFINE_string(logFile, "", "Destination for writing log output, in addition to stdout."); |
| 39 | DEFINE_bool(logPerIter, false, "Log each repeat timer instead of mean."); |
| 40 | DEFINE_bool(min, false, "Print the minimum times (instead of average)."); |
| 41 | DECLARE_int32(multi); |
| 42 | DECLARE_string(r); |
| 43 | DEFINE_int32(repeat, 1, "Set the number of times to repeat each test."); |
| 44 | DEFINE_bool(timeIndividualTiles, false, "Report times for drawing individual tiles, rather than " |
| 45 | "times for drawing the whole page. Requires tiled rendering."); |
| 46 | DEFINE_string(timers, "", "[wcgWC]*: Display wall, cpu, gpu, truncated wall or truncated cpu time" |
| 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 " |
| 49 | "LAZY_CACHE_STATS set to true. Report percentage of cache hits when using deferred " |
| 50 | "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 | |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 145 | #include "SkData.h" |
| 146 | #include "SkLruImageCache.h" |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 147 | #include "SkLazyPixelRef.h" |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 148 | |
| 149 | static SkLruImageCache gLruImageCache(1024*1024); |
| 150 | |
| 151 | static bool lazy_decode_bitmap(const void* buffer, size_t size, SkBitmap* bitmap) { |
| 152 | void* copiedBuffer = sk_malloc_throw(size); |
| 153 | memcpy(copiedBuffer, buffer, size); |
| 154 | SkAutoDataUnref data(SkData::NewFromMalloc(copiedBuffer, size)); |
| 155 | SkBitmapFactory factory(&SkImageDecoder::DecodeMemoryToTarget); |
| 156 | factory.setImageCache(&gLruImageCache); |
| 157 | return factory.installPixelRef(data, bitmap); |
| 158 | } |
| 159 | |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 160 | #if LAZY_CACHE_STATS |
| 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 | |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 177 | // Since the old picture has been deleted, all pixels should be cleared. |
| 178 | SkASSERT(gLruImageCache.getImageCacheUsed() == 0); |
| 179 | if (FLAGS_countRAM) { |
| 180 | // Set the limit to zero, so all pixels will be kept |
| 181 | gLruImageCache.setImageCacheLimit(0); |
| 182 | } |
| 183 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 184 | bool success = false; |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 185 | SkPicture* picture; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 186 | if (FLAGS_deferImageDecoding) { |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 187 | picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &lazy_decode_bitmap)); |
| 188 | } else { |
| 189 | picture = SkNEW_ARGS(SkPicture, (&inputStream, &success, &SkImageDecoder::DecodeMemory)); |
| 190 | } |
| 191 | SkAutoTDelete<SkPicture> ad(picture); |
| 192 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 193 | if (!success) { |
| 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 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 200 | SkString filename; |
| 201 | sk_tools::get_basename(&filename, inputPath); |
keyar@chromium.org | db9a5fb | 2012-08-21 17:57:59 +0000 | [diff] [blame] | 202 | |
| 203 | SkString result; |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 204 | result.printf("running bench [%i %i] %s ", picture->width(), picture->height(), |
| 205 | filename.c_str()); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 206 | gLogger.logProgress(result); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 207 | |
scroggo@google.com | f8d7d27 | 2013-02-22 21:38:35 +0000 | [diff] [blame] | 208 | benchmark.run(picture); |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 209 | |
| 210 | #if LAZY_CACHE_STATS |
| 211 | if (FLAGS_trackDeferredCaching) { |
| 212 | int32_t cacheHits = SkLazyPixelRef::GetCacheHits(); |
| 213 | int32_t cacheMisses = SkLazyPixelRef::GetCacheMisses(); |
| 214 | SkLazyPixelRef::ResetCacheStats(); |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 215 | SkString hitString; |
| 216 | hitString.printf("Cache hit rate: %f\n", (double) cacheHits / (cacheHits + cacheMisses)); |
| 217 | gLogger.logProgress(hitString); |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 218 | gTotalCacheHits += cacheHits; |
| 219 | gTotalCacheMisses += cacheMisses; |
| 220 | } |
| 221 | #endif |
scroggo@google.com | a560d00b | 2013-03-04 21:32:32 +0000 | [diff] [blame] | 222 | if (FLAGS_countRAM) { |
| 223 | SkString ramCount("RAM used for bitmaps: "); |
| 224 | size_t bytes = gLruImageCache.getImageCacheUsed(); |
| 225 | if (bytes > 1024) { |
| 226 | size_t kb = bytes / 1024; |
| 227 | if (kb > 1024) { |
| 228 | size_t mb = kb / 1024; |
| 229 | ramCount.appendf("%zi MB\n", mb); |
| 230 | } else { |
| 231 | ramCount.appendf("%zi KB\n", kb); |
| 232 | } |
| 233 | } else { |
| 234 | ramCount.appendf("%zi bytes\n", bytes); |
| 235 | } |
| 236 | gLogger.logProgress(ramCount); |
| 237 | } |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 238 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 239 | return true; |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 240 | } |
| 241 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 242 | static void setup_benchmark(sk_tools::PictureBenchmark* benchmark) { |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 243 | sk_tools::PictureRenderer::DrawFilterFlags drawFilters[SkDrawFilter::kTypeCount]; |
| 244 | sk_bzero(drawFilters, sizeof(drawFilters)); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 245 | |
| 246 | if (FLAGS_filter.count() > 0) { |
| 247 | const char* filters = FLAGS_filter[0]; |
| 248 | const char* colon = strchr(filters, ':'); |
| 249 | if (colon) { |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 250 | int32_t type = -1; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 251 | size_t typeLen = colon - filters; |
| 252 | for (size_t tIndex = 0; tIndex < kFilterTypesCount; ++tIndex) { |
| 253 | if (typeLen == strlen(gFilterTypes[tIndex]) |
| 254 | && !strncmp(filters, gFilterTypes[tIndex], typeLen)) { |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 255 | type = SkToS32(tIndex); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 256 | break; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 257 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 258 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 259 | if (type < 0) { |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 260 | SkString err; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 261 | err.printf("Unknown type for --filter %s\n", filters); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 262 | gLogger.logError(err); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 263 | exit(-1); |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 264 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 265 | int flag = -1; |
| 266 | size_t flagLen = strlen(filters) - typeLen - 1; |
| 267 | for (size_t fIndex = 0; fIndex < kFilterFlagsCount; ++fIndex) { |
| 268 | if (flagLen == strlen(gFilterFlags[fIndex]) |
| 269 | && !strncmp(colon + 1, gFilterFlags[fIndex], flagLen)) { |
| 270 | flag = 1 << fIndex; |
| 271 | break; |
| 272 | } |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 273 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 274 | if (flag < 0) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 275 | SkString err; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 276 | err.printf("Unknown flag for --filter %s\n", filters); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 277 | gLogger.logError(err); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 278 | exit(-1); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 279 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 280 | for (int index = 0; index < SkDrawFilter::kTypeCount; ++index) { |
| 281 | if (type != SkDrawFilter::kTypeCount && index != type) { |
| 282 | continue; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 283 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 284 | drawFilters[index] = (sk_tools::PictureRenderer::DrawFilterFlags) |
| 285 | (drawFilters[index] | flag); |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 286 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 287 | } else { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 288 | SkString err; |
| 289 | err.printf("Unknown arg for --filter %s : missing colon\n", filters); |
| 290 | gLogger.logError(err); |
| 291 | exit(-1); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 292 | } |
| 293 | } |
| 294 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 295 | if (FLAGS_timers.count() > 0) { |
| 296 | size_t index = 0; |
| 297 | bool timerWall = false; |
| 298 | bool truncatedTimerWall = false; |
| 299 | bool timerCpu = false; |
| 300 | bool truncatedTimerCpu = false; |
| 301 | bool timerGpu = false; |
| 302 | while (index < strlen(FLAGS_timers[0])) { |
| 303 | switch (FLAGS_timers[0][index]) { |
| 304 | case 'w': |
| 305 | timerWall = true; |
| 306 | break; |
| 307 | case 'c': |
| 308 | timerCpu = true; |
| 309 | break; |
| 310 | case 'W': |
| 311 | truncatedTimerWall = true; |
| 312 | break; |
| 313 | case 'C': |
| 314 | truncatedTimerCpu = true; |
| 315 | break; |
| 316 | case 'g': |
| 317 | timerGpu = true; |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 318 | break; |
| 319 | default: |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 320 | SkDebugf("mystery character\n"); |
scroggo@google.com | 0556ea0 | 2013-02-08 19:38:21 +0000 | [diff] [blame] | 321 | break; |
| 322 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 323 | index++; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 324 | } |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 325 | benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, truncatedTimerCpu, |
| 326 | timerGpu); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 327 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 328 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 329 | SkString errorString; |
| 330 | SkAutoTUnref<sk_tools::PictureRenderer> renderer(parseRenderer(errorString, |
| 331 | kBench_PictureTool)); |
| 332 | |
| 333 | if (errorString.size() > 0) { |
| 334 | gLogger.logError(errorString); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 335 | } |
junov@chromium.org | 9313ca4 | 2012-11-02 18:11:49 +0000 | [diff] [blame] | 336 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 337 | if (NULL == renderer.get()) { |
| 338 | exit(-1); |
| 339 | } |
| 340 | |
| 341 | if (FLAGS_timeIndividualTiles) { |
| 342 | if (FLAGS_multi > 1) { |
| 343 | gLogger.logError("Cannot time individual tiles with more than one thread.\n"); |
| 344 | exit(-1); |
| 345 | } |
| 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 | |
| 358 | if (FLAGS_r.count() < 1) { |
| 359 | gLogger.logError(".skp files or directories are required.\n"); |
| 360 | exit(-1); |
| 361 | } |
| 362 | |
caryclark@google.com | a362237 | 2012-11-06 21:26:13 +0000 | [diff] [blame] | 363 | renderer->setDrawFilters(drawFilters, filtersName(drawFilters)); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 364 | benchmark->setPrintMin(FLAGS_min); |
| 365 | benchmark->setLogPerIter(FLAGS_logPerIter); |
scroggo@google.com | a62da2f | 2012-11-02 21:28:12 +0000 | [diff] [blame] | 366 | benchmark->setRenderer(renderer); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 367 | benchmark->setRepeats(FLAGS_repeat); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 368 | benchmark->setLogger(&gLogger); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 369 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 370 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 371 | static int process_input(const char* input, |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 372 | sk_tools::PictureBenchmark& benchmark) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 373 | SkString inputAsSkString(input); |
| 374 | SkOSFile::Iter iter(input, "skp"); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 375 | SkString inputFilename; |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 376 | int failures = 0; |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 377 | if (iter.next(&inputFilename)) { |
| 378 | do { |
| 379 | SkString inputPath; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 380 | sk_tools::make_filepath(&inputPath, inputAsSkString, inputFilename); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 381 | if (!run_single_benchmark(inputPath, 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 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 384 | } while(iter.next(&inputFilename)); |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 385 | } else if (SkStrEndsWith(input, ".skp")) { |
| 386 | if (!run_single_benchmark(inputAsSkString, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 387 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 388 | } |
| 389 | } else { |
| 390 | SkString warning; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 391 | warning.printf("Warning: skipping %s\n", input); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 392 | gLogger.logError(warning); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 393 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 394 | return failures; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 395 | } |
| 396 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 397 | int tool_main(int argc, char** argv); |
| 398 | int tool_main(int argc, char** argv) { |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 399 | SkString usage; |
| 400 | usage.printf("Time drawing .skp files.\n" |
| 401 | "\tPossible arguments for --filter: [%s]\n\t\t[%s]", |
| 402 | filterTypesUsage().c_str(), filterFlagsUsage().c_str()); |
| 403 | SkFlags::SetUsage(usage.c_str()); |
| 404 | SkFlags::ParseCommandLine(argc, argv); |
| 405 | |
| 406 | if (FLAGS_repeat < 1) { |
| 407 | SkString error; |
| 408 | error.printf("--repeats must be >= 1. Was %i\n", FLAGS_repeat); |
| 409 | gLogger.logError(error); |
| 410 | exit(-1); |
| 411 | } |
| 412 | |
| 413 | if (FLAGS_logFile.count() == 1) { |
| 414 | if (!gLogger.SetLogFile(FLAGS_logFile[0])) { |
| 415 | SkString str; |
| 416 | str.printf("Could not open %s for writing.\n", FLAGS_logFile[0]); |
| 417 | gLogger.logError(str); |
| 418 | // TODO(borenet): We're disabling this for now, due to |
| 419 | // write-protected Android devices. The very short-term |
| 420 | // solution is to ignore the fact that we have no log file. |
| 421 | //exit(-1); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | |
bsalomon@google.com | 4e23068 | 2013-01-15 20:37:04 +0000 | [diff] [blame] | 426 | #if SK_ENABLE_INST_COUNT |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 427 | gPrintInstCount = true; |
| 428 | #endif |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 429 | SkAutoGraphics ag; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 430 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 431 | sk_tools::PictureBenchmark benchmark; |
| 432 | |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 433 | setup_benchmark(&benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 434 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 435 | int failures = 0; |
scroggo@google.com | 161e1ba | 2013-03-04 16:41:06 +0000 | [diff] [blame] | 436 | for (int i = 0; i < FLAGS_r.count(); ++i) { |
| 437 | failures += process_input(FLAGS_r[i], benchmark); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | if (failures != 0) { |
| 441 | SkString err; |
| 442 | err.printf("Failed to run %i benchmarks.\n", failures); |
| 443 | gLogger.logError(err); |
| 444 | return 1; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 445 | } |
scroggo@google.com | cc69020 | 2013-03-04 19:56:21 +0000 | [diff] [blame] | 446 | #if LAZY_CACHE_STATS |
| 447 | if (FLAGS_trackDeferredCaching) { |
| 448 | SkDebugf("Total cache hit rate: %f\n", |
| 449 | (double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses)); |
| 450 | } |
| 451 | #endif |
caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 452 | return 0; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 453 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 454 | |
| 455 | #if !defined SK_BUILD_FOR_IOS |
| 456 | int main(int argc, char * const argv[]) { |
| 457 | return tool_main(argc, (char**) argv); |
| 458 | } |
| 459 | #endif |