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