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