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