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" |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 9 | #include "PictureBenchmark.h" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 10 | #include "SkBenchLogger.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 12 | #include "SkGraphics.h" |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 13 | #include "SkImageDecoder.h" |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 14 | #include "SkMath.h" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 15 | #include "SkOSFile.h" |
| 16 | #include "SkPicture.h" |
| 17 | #include "SkStream.h" |
| 18 | #include "SkTArray.h" |
| 19 | #include "picture_utils.h" |
| 20 | |
borenet@google.com | 13fd5a1 | 2012-09-17 21:10:05 +0000 | [diff] [blame] | 21 | const int DEFAULT_REPEATS = 1; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 22 | |
| 23 | static void usage(const char* argv0) { |
| 24 | SkDebugf("SkPicture benchmarking tool\n"); |
| 25 | SkDebugf("\n" |
| 26 | "Usage: \n" |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 27 | " %s <inputDir>...\n" |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 28 | " [--logFile filename][--timers [wcgWC]*][--logPerIter 1|0][--min]\n" |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 29 | " [--repeat] \n" |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 30 | " [--mode pow2tile minWidth height[] | record | simple\n" |
| 31 | " | tile width[] height[] | playbackCreation]\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 32 | " [--pipe]\n" |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 33 | " [--multi numThreads]\n" |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 34 | " [--device bitmap" |
| 35 | #if SK_SUPPORT_GPU |
| 36 | " | gpu" |
| 37 | #endif |
| 38 | "]" |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 39 | , argv0); |
| 40 | SkDebugf("\n\n"); |
| 41 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 42 | " inputDir: A list of directories and files to use as input. Files are\n" |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 43 | " expected to have the .skp extension.\n\n" |
| 44 | " --logFile filename : destination for writing log output, in addition to stdout.\n"); |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 45 | SkDebugf(" --logPerIter 1|0 : " |
| 46 | "Log each repeat timer instead of mean, default is disabled.\n"); |
| 47 | SkDebugf(" --min : Print the minimum times (instead of average).\n"); |
| 48 | SkDebugf(" --timers [wcgWC]* : " |
| 49 | "Display wall, cpu, gpu, truncated wall or truncated cpu time for each picture.\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 50 | SkDebugf( |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 51 | " --mode pow2tile minWidht height[] | record | simple\n" |
| 52 | " | tile width[] height[] | playbackCreation:\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 53 | " Run in the corresponding mode.\n" |
| 54 | " Default is simple.\n"); |
keyar@chromium.org | cf6c44c | 2012-07-09 19:37:40 +0000 | [diff] [blame] | 55 | SkDebugf( |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 56 | " pow2tile minWidth height[], Creates tiles with widths\n" |
| 57 | " that are all a power of two\n" |
| 58 | " such that they minimize the\n" |
| 59 | " amount of wasted tile space.\n" |
| 60 | " minWidth is the minimum width\n" |
| 61 | " of these tiles and must be a\n" |
| 62 | " power of two. Simple\n" |
| 63 | " rendering using these tiles\n" |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 64 | " is benchmarked.\n"); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 65 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 66 | " record, Benchmark picture to picture recording.\n"); |
| 67 | SkDebugf( |
| 68 | " simple, Benchmark a simple rendering.\n"); |
| 69 | SkDebugf( |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 70 | " tile width[] height[], Benchmark simple rendering using\n" |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 71 | " tiles with the given dimensions.\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 72 | SkDebugf( |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 73 | " playbackCreation, Benchmark creation of the SkPicturePlayback.\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 74 | SkDebugf("\n"); |
| 75 | SkDebugf( |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 76 | " --multi numThreads : Set the number of threads for multi threaded drawing. Must be greater\n" |
| 77 | " than 1. Only works with tiled rendering.\n" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 78 | " --pipe: Benchmark SkGPipe rendering. Compatible with tiled, multithreaded rendering.\n"); |
| 79 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 80 | " --device bitmap" |
| 81 | #if SK_SUPPORT_GPU |
| 82 | " | gpu" |
| 83 | #endif |
| 84 | ": Use the corresponding device. Default is bitmap.\n"); |
| 85 | SkDebugf( |
| 86 | " bitmap, Render to a bitmap.\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 87 | #if SK_SUPPORT_GPU |
keyar@chromium.org | a40c20d | 2012-08-20 15:04:12 +0000 | [diff] [blame] | 88 | SkDebugf( |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 89 | " gpu, Render to the GPU.\n"); |
| 90 | #endif |
| 91 | SkDebugf("\n"); |
| 92 | SkDebugf( |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 93 | " --repeat: " |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 94 | "Set the number of times to repeat each test." |
| 95 | " Default is %i.\n", DEFAULT_REPEATS); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 96 | } |
| 97 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 98 | SkBenchLogger gLogger; |
| 99 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 100 | static bool run_single_benchmark(const SkString& inputPath, |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 101 | sk_tools::PictureBenchmark& benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 102 | SkFILEStream inputStream; |
| 103 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 104 | inputStream.setPath(inputPath.c_str()); |
| 105 | if (!inputStream.isValid()) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 106 | SkString err; |
| 107 | err.printf("Could not open file %s\n", inputPath.c_str()); |
| 108 | gLogger.logError(err); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 109 | return false; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 110 | } |
| 111 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 112 | bool success = false; |
scroggo@google.com | 5a7c6be | 2012-10-04 21:46:08 +0000 | [diff] [blame] | 113 | SkPicture picture(&inputStream, &success, &SkImageDecoder::DecodeStream); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 114 | if (!success) { |
| 115 | SkString err; |
| 116 | err.printf("Could not read an SkPicture from %s\n", inputPath.c_str()); |
| 117 | gLogger.logError(err); |
| 118 | return false; |
| 119 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 120 | |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 121 | SkString filename; |
| 122 | sk_tools::get_basename(&filename, inputPath); |
keyar@chromium.org | db9a5fb | 2012-08-21 17:57:59 +0000 | [diff] [blame] | 123 | |
| 124 | SkString result; |
borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 125 | result.printf("running bench [%i %i] %s ", picture.width(), |
| 126 | picture.height(), filename.c_str()); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 127 | gLogger.logProgress(result); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 128 | |
borenet@google.com | 2d2b9a0 | 2012-09-20 18:54:04 +0000 | [diff] [blame] | 129 | benchmark.run(&picture); |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 130 | return true; |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 131 | } |
| 132 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 133 | static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>* inputs, |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 134 | sk_tools::PictureBenchmark* benchmark) { |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 135 | const char* argv0 = argv[0]; |
| 136 | char* const* stop = argv + argc; |
| 137 | |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 138 | int repeats = DEFAULT_REPEATS; |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 139 | sk_tools::PictureRenderer::SkDeviceTypes deviceType = |
| 140 | sk_tools::PictureRenderer::kBitmap_DeviceType; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 141 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 142 | sk_tools::PictureRenderer* renderer = NULL; |
| 143 | |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 144 | // Create a string to show our current settings. |
| 145 | // TODO: Make it prettier. Currently it just repeats the command line. |
| 146 | SkString commandLine("bench_pictures:"); |
| 147 | for (int i = 1; i < argc; i++) { |
| 148 | commandLine.appendf(" %s", *(argv+i)); |
| 149 | } |
| 150 | commandLine.append("\n"); |
| 151 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 152 | bool usePipe = false; |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 153 | int numThreads = 1; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 154 | bool useTiles = false; |
| 155 | const char* widthString = NULL; |
| 156 | const char* heightString = NULL; |
| 157 | bool isPowerOf2Mode = false; |
| 158 | const char* mode = NULL; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 159 | for (++argv; argv < stop; ++argv) { |
| 160 | if (0 == strcmp(*argv, "--repeat")) { |
| 161 | ++argv; |
| 162 | if (argv < stop) { |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 163 | repeats = atoi(*argv); |
| 164 | if (repeats < 1) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 165 | gLogger.logError("--repeat must be given a value > 0\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 166 | exit(-1); |
| 167 | } |
| 168 | } else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 169 | gLogger.logError("Missing arg for --repeat\n"); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 170 | usage(argv0); |
| 171 | exit(-1); |
| 172 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 173 | } else if (0 == strcmp(*argv, "--pipe")) { |
| 174 | usePipe = true; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 175 | } else if (0 == strcmp(*argv, "--logFile")) { |
| 176 | argv++; |
| 177 | if (argv < stop) { |
| 178 | if (!gLogger.SetLogFile(*argv)) { |
| 179 | SkString str; |
| 180 | str.printf("Could not open %s for writing.", *argv); |
| 181 | gLogger.logError(str); |
| 182 | usage(argv0); |
borenet@google.com | a49bffd | 2012-09-13 18:54:48 +0000 | [diff] [blame] | 183 | // TODO(borenet): We're disabling this for now, due to |
| 184 | // write-protected Android devices. The very short-term |
| 185 | // solution is to ignore the fact that we have no log file. |
| 186 | //exit(-1); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 187 | } |
| 188 | } else { |
| 189 | gLogger.logError("Missing arg for --logFile\n"); |
| 190 | usage(argv0); |
| 191 | exit(-1); |
| 192 | } |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 193 | } else if (0 == strcmp(*argv, "--multi")) { |
| 194 | ++argv; |
| 195 | if (argv >= stop) { |
| 196 | gLogger.logError("Missing arg for --multi\n"); |
| 197 | usage(argv0); |
| 198 | exit(-1); |
| 199 | } |
| 200 | numThreads = atoi(*argv); |
| 201 | if (numThreads < 2) { |
| 202 | gLogger.logError("Number of threads must be at least 2.\n"); |
| 203 | usage(argv0); |
| 204 | exit(-1); |
| 205 | } |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 206 | } else if (0 == strcmp(*argv, "--mode")) { |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 207 | |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 208 | ++argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 209 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 210 | gLogger.logError("Missing mode for --mode\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 211 | usage(argv0); |
| 212 | exit(-1); |
| 213 | } |
| 214 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 215 | if (0 == strcmp(*argv, "record")) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 216 | renderer = SkNEW(sk_tools::RecordPictureRenderer); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 217 | } else if (0 == strcmp(*argv, "simple")) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 218 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 219 | } else if ((0 == strcmp(*argv, "tile")) || (0 == strcmp(*argv, "pow2tile"))) { |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 220 | useTiles = true; |
| 221 | mode = *argv; |
keyar@chromium.org | f4959ab | 2012-08-23 20:53:25 +0000 | [diff] [blame] | 222 | |
| 223 | if (0 == strcmp(*argv, "pow2tile")) { |
| 224 | isPowerOf2Mode = true; |
| 225 | } |
| 226 | |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 227 | ++argv; |
| 228 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 229 | SkString err; |
| 230 | err.printf("Missing width for --mode %s\n", mode); |
| 231 | gLogger.logError(err); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 232 | usage(argv0); |
| 233 | exit(-1); |
| 234 | } |
| 235 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 236 | widthString = *argv; |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 237 | ++argv; |
| 238 | if (argv >= stop) { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 239 | gLogger.logError("Missing height for --mode tile\n"); |
keyar@chromium.org | 795cd47 | 2012-08-02 18:57:53 +0000 | [diff] [blame] | 240 | usage(argv0); |
| 241 | exit(-1); |
| 242 | } |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 243 | heightString = *argv; |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 244 | } else if (0 == strcmp(*argv, "playbackCreation")) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 245 | renderer = SkNEW(sk_tools::PlaybackCreationRenderer); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 246 | } else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 247 | SkString err; |
| 248 | err.printf("%s is not a valid mode for --mode\n", *argv); |
| 249 | gLogger.logError(err); |
keyar@chromium.org | 0665f25 | 2012-07-10 18:30:18 +0000 | [diff] [blame] | 250 | usage(argv0); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 251 | exit(-1); |
| 252 | } |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 253 | } else if (0 == strcmp(*argv, "--device")) { |
| 254 | ++argv; |
| 255 | if (argv >= stop) { |
borenet@google.com | a49bffd | 2012-09-13 18:54:48 +0000 | [diff] [blame] | 256 | gLogger.logError("Missing mode for --device\n"); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 257 | usage(argv0); |
| 258 | exit(-1); |
| 259 | } |
| 260 | |
| 261 | if (0 == strcmp(*argv, "bitmap")) { |
| 262 | deviceType = sk_tools::PictureRenderer::kBitmap_DeviceType; |
| 263 | } |
| 264 | #if SK_SUPPORT_GPU |
| 265 | else if (0 == strcmp(*argv, "gpu")) { |
| 266 | deviceType = sk_tools::PictureRenderer::kGPU_DeviceType; |
| 267 | } |
| 268 | #endif |
| 269 | else { |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 270 | SkString err; |
| 271 | err.printf("%s is not a valid mode for --device\n", *argv); |
| 272 | gLogger.logError(err); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 273 | usage(argv0); |
| 274 | exit(-1); |
| 275 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 276 | } else if (0 == strcmp(*argv, "--timers")) { |
| 277 | ++argv; |
| 278 | if (argv < stop) { |
| 279 | bool timerWall = false; |
| 280 | bool truncatedTimerWall = false; |
| 281 | bool timerCpu = false; |
| 282 | bool truncatedTimerCpu = false; |
| 283 | bool timerGpu = false; |
| 284 | for (char* t = *argv; *t; ++t) { |
| 285 | switch (*t) { |
| 286 | case 'w': |
| 287 | timerWall = true; |
| 288 | break; |
| 289 | case 'c': |
| 290 | timerCpu = true; |
| 291 | break; |
| 292 | case 'W': |
| 293 | truncatedTimerWall = true; |
| 294 | break; |
| 295 | case 'C': |
| 296 | truncatedTimerCpu = true; |
| 297 | break; |
| 298 | case 'g': |
| 299 | timerGpu = true; |
| 300 | break; |
| 301 | default: { |
| 302 | break; |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | benchmark->setTimersToShow(timerWall, truncatedTimerWall, timerCpu, |
| 307 | truncatedTimerCpu, timerGpu); |
| 308 | } else { |
| 309 | gLogger.logError("Missing arg for --timers\n"); |
| 310 | usage(argv0); |
| 311 | exit(-1); |
| 312 | } |
| 313 | } else if (0 == strcmp(*argv, "--min")) { |
| 314 | benchmark->setPrintMin(true); |
| 315 | } else if (0 == strcmp(*argv, "--logPerIter")) { |
| 316 | ++argv; |
| 317 | if (argv < stop) { |
| 318 | bool log = atoi(*argv) != 0; |
| 319 | benchmark->setLogPerIter(log); |
| 320 | } else { |
| 321 | gLogger.logError("Missing arg for --logPerIter\n"); |
| 322 | usage(argv0); |
| 323 | exit(-1); |
| 324 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 325 | } else if (0 == strcmp(*argv, "--help") || 0 == strcmp(*argv, "-h")) { |
| 326 | usage(argv0); |
| 327 | exit(0); |
| 328 | } else { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 329 | inputs->push_back(SkString(*argv)); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 330 | } |
| 331 | } |
| 332 | |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 333 | if (numThreads > 1 && !useTiles) { |
| 334 | gLogger.logError("Multithreaded drawing requires tiled rendering.\n"); |
| 335 | usage(argv0); |
| 336 | exit(-1); |
| 337 | } |
| 338 | |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 339 | if (useTiles) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 340 | SkASSERT(NULL == renderer); |
| 341 | sk_tools::TiledPictureRenderer* tiledRenderer = SkNEW(sk_tools::TiledPictureRenderer); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 342 | if (isPowerOf2Mode) { |
| 343 | int minWidth = atoi(widthString); |
| 344 | if (!SkIsPow2(minWidth) || minWidth < 0) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 345 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 346 | SkString err; |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 347 | err.printf("-mode %s must be given a width" |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 348 | " value that is a power of two\n", mode); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 349 | gLogger.logError(err); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 350 | usage(argv0); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 351 | exit(-1); |
| 352 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 353 | tiledRenderer->setTileMinPowerOf2Width(minWidth); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 354 | } else if (sk_tools::is_percentage(widthString)) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 355 | tiledRenderer->setTileWidthPercentage(atof(widthString)); |
| 356 | if (!(tiledRenderer->getTileWidthPercentage() > 0)) { |
| 357 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 358 | gLogger.logError("--mode tile must be given a width percentage > 0\n"); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 359 | usage(argv0); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 360 | exit(-1); |
| 361 | } |
| 362 | } else { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 363 | tiledRenderer->setTileWidth(atoi(widthString)); |
| 364 | if (!(tiledRenderer->getTileWidth() > 0)) { |
| 365 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 366 | gLogger.logError("--mode tile must be given a width > 0\n"); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 367 | usage(argv0); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 368 | exit(-1); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | if (sk_tools::is_percentage(heightString)) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 373 | tiledRenderer->setTileHeightPercentage(atof(heightString)); |
| 374 | if (!(tiledRenderer->getTileHeightPercentage() > 0)) { |
| 375 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 376 | gLogger.logError("--mode tile must be given a height percentage > 0\n"); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 377 | usage(argv0); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 378 | exit(-1); |
| 379 | } |
| 380 | } else { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 381 | tiledRenderer->setTileHeight(atoi(heightString)); |
| 382 | if (!(tiledRenderer->getTileHeight() > 0)) { |
| 383 | tiledRenderer->unref(); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 384 | gLogger.logError("--mode tile must be given a height > 0\n"); |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 385 | usage(argv0); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 386 | exit(-1); |
| 387 | } |
| 388 | } |
scroggo@google.com | bcdf2ec | 2012-09-20 14:42:33 +0000 | [diff] [blame] | 389 | if (numThreads > 1) { |
| 390 | #if SK_SUPPORT_GPU |
| 391 | if (sk_tools::PictureRenderer::kGPU_DeviceType == deviceType) { |
| 392 | tiledRenderer->unref(); |
| 393 | gLogger.logError("GPU not compatible with multithreaded tiling.\n"); |
| 394 | usage(argv0); |
| 395 | exit(-1); |
| 396 | } |
| 397 | #endif |
| 398 | tiledRenderer->setNumberOfThreads(numThreads); |
| 399 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 400 | tiledRenderer->setUsePipe(usePipe); |
| 401 | renderer = tiledRenderer; |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 402 | } else if (usePipe) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 403 | renderer = SkNEW(sk_tools::PipePictureRenderer); |
scroggo@google.com | 58b4ead | 2012-08-31 16:15:22 +0000 | [diff] [blame] | 404 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 405 | if (inputs->count() < 1) { |
fmalita@google.com | c6157be | 2012-09-27 13:09:58 +0000 | [diff] [blame] | 406 | SkSafeUnref(renderer); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 407 | usage(argv0); |
| 408 | exit(-1); |
| 409 | } |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 410 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 411 | if (NULL == renderer) { |
| 412 | renderer = SkNEW(sk_tools::SimplePictureRenderer); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 413 | } |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 414 | benchmark->setRenderer(renderer)->unref(); |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 415 | benchmark->setRepeats(repeats); |
keyar@chromium.org | c81686c | 2012-08-20 15:04:04 +0000 | [diff] [blame] | 416 | benchmark->setDeviceType(deviceType); |
scroggo@google.com | 9a41252 | 2012-09-07 15:21:18 +0000 | [diff] [blame] | 417 | benchmark->setLogger(&gLogger); |
| 418 | // Report current settings: |
| 419 | gLogger.logProgress(commandLine); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 420 | } |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 421 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 422 | static int process_input(const SkString& input, |
| 423 | sk_tools::PictureBenchmark& benchmark) { |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 424 | SkOSFile::Iter iter(input.c_str(), "skp"); |
| 425 | SkString inputFilename; |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 426 | int failures = 0; |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 427 | if (iter.next(&inputFilename)) { |
| 428 | do { |
| 429 | SkString inputPath; |
keyar@chromium.org | 163b567 | 2012-08-01 17:53:29 +0000 | [diff] [blame] | 430 | sk_tools::make_filepath(&inputPath, input, inputFilename); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 431 | if (!run_single_benchmark(inputPath, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 432 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 433 | } |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 434 | } while(iter.next(&inputFilename)); |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 435 | } else if (SkStrEndsWith(input.c_str(), ".skp")) { |
| 436 | if (!run_single_benchmark(input, benchmark)) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 437 | ++failures; |
borenet@google.com | 57837bf | 2012-09-19 17:28:29 +0000 | [diff] [blame] | 438 | } |
| 439 | } else { |
| 440 | SkString warning; |
| 441 | warning.printf("Warning: skipping %s\n", input.c_str()); |
| 442 | gLogger.logError(warning); |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 443 | } |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 444 | return failures; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 445 | } |
| 446 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 447 | int tool_main(int argc, char** argv); |
| 448 | int tool_main(int argc, char** argv) { |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 449 | #ifdef SK_ENABLE_INST_COUNT |
| 450 | gPrintInstCount = true; |
| 451 | #endif |
scroggo@google.com | 0a36f43 | 2012-09-10 20:29:13 +0000 | [diff] [blame] | 452 | SkAutoGraphics ag; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 453 | |
scroggo@google.com | 5239c32 | 2012-09-11 19:15:32 +0000 | [diff] [blame] | 454 | SkTArray<SkString> inputs; |
| 455 | sk_tools::PictureBenchmark benchmark; |
| 456 | |
| 457 | parse_commandline(argc, argv, &inputs, &benchmark); |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 458 | |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 459 | int failures = 0; |
keyar@chromium.org | d1dc920 | 2012-07-09 18:32:08 +0000 | [diff] [blame] | 460 | for (int i = 0; i < inputs.count(); ++i) { |
borenet@google.com | 66bcbd1 | 2012-09-17 18:26:06 +0000 | [diff] [blame] | 461 | failures += process_input(inputs[i], benchmark); |
| 462 | } |
| 463 | |
| 464 | if (failures != 0) { |
| 465 | SkString err; |
| 466 | err.printf("Failed to run %i benchmarks.\n", failures); |
| 467 | gLogger.logError(err); |
| 468 | return 1; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 469 | } |
caryclark@google.com | 868e1f6 | 2012-10-02 20:00:03 +0000 | [diff] [blame] | 470 | return 0; |
reed@google.com | 006db0f | 2012-06-27 19:33:29 +0000 | [diff] [blame] | 471 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 472 | |
| 473 | #if !defined SK_BUILD_FOR_IOS |
| 474 | int main(int argc, char * const argv[]) { |
| 475 | return tool_main(argc, (char**) argv); |
| 476 | } |
| 477 | #endif |