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 "../include/record/SkRecording.h" | 17 #include "../include/record/SkRecording.h" |
18 | 18 |
19 #include "BenchTimer.h" | |
20 #include "Stats.h" | 19 #include "Stats.h" |
21 | 20 #include "Timer.h" |
22 typedef WallTimer Timer; | |
23 | 21 |
24 __SK_FORCE_IMAGE_DECODER_LINKING; | 22 __SK_FORCE_IMAGE_DECODER_LINKING; |
25 | 23 |
26 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback."); | 24 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback."); |
27 DEFINE_int32(samples, 10, "Gather this many samples of each picture playback."); | 25 DEFINE_int32(samples, 10, "Gather this many samples of each picture playback."); |
28 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | 26 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); |
29 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 27 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
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, "ms", "Print times in ms, us, or ns"); | 29 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); |
32 DEFINE_int32(verbose, 0, "0: print min sample; " | 30 DEFINE_int32(verbose, 0, "0: print min sample; " |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 69 |
72 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), | 70 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), |
73 src.height(), | 71 src.height(), |
74 scratch, | 72 scratch, |
75 src.width() * si
zeof(SkPMColor))); | 73 src.width() * si
zeof(SkPMColor))); |
76 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); | 74 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); |
77 | 75 |
78 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. | 76 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. |
79 draw(*record, *picture, canvas.get()); | 77 draw(*record, *picture, canvas.get()); |
80 | 78 |
81 Timer timer; | 79 WallTimer timer; |
| 80 const double scale = timescale(); |
82 SkAutoTMalloc<double> samples(FLAGS_samples); | 81 SkAutoTMalloc<double> samples(FLAGS_samples); |
83 for (int i = 0; i < FLAGS_samples; i++) { | 82 for (int i = 0; i < FLAGS_samples; i++) { |
84 // We assume timer overhead (typically, ~30ns) is insignificant | 83 // We assume timer overhead (typically, ~30ns) is insignificant |
85 // compared to draw runtime (at least ~100us, usually several ms). | 84 // compared to draw runtime (at least ~100us, usually several ms). |
86 timer.start(timescale()); | 85 timer.start(); |
87 draw(*record, *picture, canvas.get()); | 86 draw(*record, *picture, canvas.get()); |
88 timer.end(); | 87 timer.end(); |
89 samples[i] = timer.fWall; | 88 samples[i] = timer.fWall * scale; |
90 } | 89 } |
91 | 90 |
92 Stats stats(samples.get(), FLAGS_samples); | 91 Stats stats(samples.get(), FLAGS_samples); |
93 if (FLAGS_verbose == 0) { | 92 if (FLAGS_verbose == 0) { |
94 printf("%g\t%s\n", stats.min, name); | 93 printf("%g\t%s\n", stats.min, name); |
95 } else if (FLAGS_verbose == 1) { | 94 } else if (FLAGS_verbose == 1) { |
96 // Get a rough idea of how noisy the measurements were. | 95 // Get a rough idea of how noisy the measurements were. |
97 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; | 96 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; |
98 printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, no
isePercent, name); | 97 printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, no
isePercent, name); |
99 } else if (FLAGS_verbose == 2) { | 98 } else if (FLAGS_verbose == 2) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 bench(scratch.get(), *src, filename.c_str()); | 146 bench(scratch.get(), *src, filename.c_str()); |
148 } | 147 } |
149 return failed ? 1 : 0; | 148 return failed ? 1 : 0; |
150 } | 149 } |
151 | 150 |
152 #if !defined SK_BUILD_FOR_IOS | 151 #if !defined SK_BUILD_FOR_IOS |
153 int main(int argc, char * const argv[]) { | 152 int main(int argc, char * const argv[]) { |
154 return tool_main(argc, (char**) argv); | 153 return tool_main(argc, (char**) argv); |
155 } | 154 } |
156 #endif | 155 #endif |
OLD | NEW |