| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
| 9 #include "SkForceLinking.h" | 9 #include "SkForceLinking.h" |
| 10 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
| 11 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
| 12 #include "SkPicture.h" | 12 #include "SkPicture.h" |
| 13 #include "SkPictureRecorder.h" | 13 #include "SkPictureRecorder.h" |
| 14 #include "SkStream.h" | 14 #include "SkStream.h" |
| 15 #include "SkString.h" | 15 #include "SkString.h" |
| 16 | 16 |
| 17 #include "BenchTimer.h" | |
| 18 #include "LazyDecodeBitmap.h" | 17 #include "LazyDecodeBitmap.h" |
| 19 #include "Stats.h" | 18 #include "Stats.h" |
| 20 | 19 #include "Timer.h" |
| 21 typedef WallTimer Timer; | |
| 22 | 20 |
| 23 __SK_FORCE_IMAGE_DECODER_LINKING; | 21 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 24 | 22 |
| 25 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); | 23 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record
."); |
| 26 DEFINE_int32(samples, 10, "Number of times to re-record each SKP."); | 24 DEFINE_int32(samples, 10, "Number of times to re-record each SKP."); |
| 27 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is
not set to tilegrid."); | 25 DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is
not set to tilegrid."); |
| 28 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg
rid, quadtree"); | 26 DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tileg
rid, quadtree"); |
| 29 DEFINE_bool(skr, false, "Record SKR instead of SKP."); | 27 DEFINE_bool(skr, false, "Record SKR instead of SKP."); |
| 30 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); | 28 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); |
| 31 DEFINE_string(timescale, "us", "Print times in ms, us, or ns"); | 29 DEFINE_string(timescale, "us", "Print times in ms, us, or ns"); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 72 } |
| 75 | 73 |
| 76 static void bench_record(const SkPicture& src, | 74 static void bench_record(const SkPicture& src, |
| 77 const double timerOverhead, | 75 const double timerOverhead, |
| 78 const char* name, | 76 const char* name, |
| 79 SkBBHFactory* bbhFactory) { | 77 SkBBHFactory* bbhFactory) { |
| 80 // Rerecord once to warm up any caches. Otherwise the first sample can be v
ery noisy. | 78 // Rerecord once to warm up any caches. Otherwise the first sample can be v
ery noisy. |
| 81 rerecord(src, bbhFactory); | 79 rerecord(src, bbhFactory); |
| 82 | 80 |
| 83 // Rerecord once to see how many times we should loop to make timer overhead
insignificant. | 81 // Rerecord once to see how many times we should loop to make timer overhead
insignificant. |
| 84 Timer timer; | 82 WallTimer timer; |
| 83 const double scale = timescale(); |
| 85 do { | 84 do { |
| 86 timer.start(timescale()); | 85 timer.start(); |
| 87 rerecord(src, bbhFactory); | 86 rerecord(src, bbhFactory); |
| 88 timer.end(); | 87 timer.end(); |
| 89 } while (timer.fWall < timerOverhead); // Loop just in case something biza
rre happens. | 88 } while (timer.fWall * scale < timerOverhead); // Loop just in case somethi
ng bizarre happens. |
| 90 | 89 |
| 91 // We want (timer overhead / measurement) to be less than FLAGS_overheadGoal
. | 90 // We want (timer overhead / measurement) to be less than FLAGS_overheadGoal
. |
| 92 // So in each sample, we'll loop enough times to have made that true for our
first measurement. | 91 // So in each sample, we'll loop enough times to have made that true for our
first measurement. |
| 93 const int loops = (int)ceil(timerOverhead / timer.fWall / FLAGS_overheadGoal
); | 92 const int loops = (int)ceil(timerOverhead / timer.fWall / FLAGS_overheadGoal
); |
| 94 | 93 |
| 95 SkAutoTMalloc<double> samples(FLAGS_samples); | 94 SkAutoTMalloc<double> samples(FLAGS_samples); |
| 96 for (int i = 0; i < FLAGS_samples; i++) { | 95 for (int i = 0; i < FLAGS_samples; i++) { |
| 97 timer.start(timescale()); | 96 timer.start(); |
| 98 for (int j = 0; j < loops; j++) { | 97 for (int j = 0; j < loops; j++) { |
| 99 rerecord(src, bbhFactory); | 98 rerecord(src, bbhFactory); |
| 100 } | 99 } |
| 101 timer.end(); | 100 timer.end(); |
| 102 samples[i] = timer.fWall / loops; | 101 samples[i] = timer.fWall * scale / loops; |
| 103 } | 102 } |
| 104 | 103 |
| 105 Stats stats(samples.get(), FLAGS_samples); | 104 Stats stats(samples.get(), FLAGS_samples); |
| 106 if (FLAGS_verbose == 0) { | 105 if (FLAGS_verbose == 0) { |
| 107 printf("%g\t%s\n", stats.min, name); | 106 printf("%g\t%s\n", stats.min, name); |
| 108 } else if (FLAGS_verbose == 1) { | 107 } else if (FLAGS_verbose == 1) { |
| 109 // Get a rough idea of how noisy the measurements were. | 108 // Get a rough idea of how noisy the measurements were. |
| 110 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; | 109 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; |
| 111 printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, no
isePercent, name); | 110 printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, no
isePercent, name); |
| 112 } else if (FLAGS_verbose == 2) { | 111 } else if (FLAGS_verbose == 2) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 125 | 124 |
| 126 if (FLAGS_bbh.count() > 1) { | 125 if (FLAGS_bbh.count() > 1) { |
| 127 SkDebugf("Multiple bbh arguments supplied.\n"); | 126 SkDebugf("Multiple bbh arguments supplied.\n"); |
| 128 return 1; | 127 return 1; |
| 129 } | 128 } |
| 130 | 129 |
| 131 SkAutoTDelete<SkBBHFactory> bbhFactory(parse_FLAGS_bbh()); | 130 SkAutoTDelete<SkBBHFactory> bbhFactory(parse_FLAGS_bbh()); |
| 132 | 131 |
| 133 // Each run will use this timer overhead estimate to guess how many times it
should run. | 132 // Each run will use this timer overhead estimate to guess how many times it
should run. |
| 134 static const int kOverheadLoops = 10000000; | 133 static const int kOverheadLoops = 10000000; |
| 135 Timer timer; | 134 WallTimer timer; |
| 136 double overheadEstimate = 0.0; | 135 double overheadEstimate = 0.0; |
| 136 const double scale = timescale(); |
| 137 for (int i = 0; i < kOverheadLoops; i++) { | 137 for (int i = 0; i < kOverheadLoops; i++) { |
| 138 timer.start(timescale()); | 138 timer.start(); |
| 139 timer.end(); | 139 timer.end(); |
| 140 overheadEstimate += timer.fWall; | 140 overheadEstimate += timer.fWall * scale; |
| 141 } | 141 } |
| 142 overheadEstimate /= kOverheadLoops; | 142 overheadEstimate /= kOverheadLoops; |
| 143 | 143 |
| 144 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | 144 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
| 145 SkString filename; | 145 SkString filename; |
| 146 bool failed = false; | 146 bool failed = false; |
| 147 while (it.next(&filename)) { | 147 while (it.next(&filename)) { |
| 148 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) { | 148 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) { |
| 149 continue; | 149 continue; |
| 150 } | 150 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 167 bench_record(*src, overheadEstimate, filename.c_str(), bbhFactory.get())
; | 167 bench_record(*src, overheadEstimate, filename.c_str(), bbhFactory.get())
; |
| 168 } | 168 } |
| 169 return failed ? 1 : 0; | 169 return failed ? 1 : 0; |
| 170 } | 170 } |
| 171 | 171 |
| 172 #if !defined SK_BUILD_FOR_IOS | 172 #if !defined SK_BUILD_FOR_IOS |
| 173 int main(int argc, char * const argv[]) { | 173 int main(int argc, char * const argv[]) { |
| 174 return tool_main(argc, (char**) argv); | 174 return tool_main(argc, (char**) argv); |
| 175 } | 175 } |
| 176 #endif | 176 #endif |
| OLD | NEW |