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