Chromium Code Reviews| 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 "BenchTimer.h" | |
| 9 #include "SkCommandLineFlags.h" | 8 #include "SkCommandLineFlags.h" |
| 10 #include "SkForceLinking.h" | 9 #include "SkForceLinking.h" |
| 11 #include "SkGraphics.h" | 10 #include "SkGraphics.h" |
| 12 #include "SkOSFile.h" | 11 #include "SkOSFile.h" |
| 13 #include "SkPicture.h" | 12 #include "SkPicture.h" |
| 14 #include "SkPictureRecorder.h" | 13 #include "SkPictureRecorder.h" |
| 15 #include "SkRecording.h" | 14 #include "SkRecording.h" |
| 16 #include "SkStream.h" | 15 #include "SkStream.h" |
| 17 #include "SkString.h" | 16 #include "SkString.h" |
| 18 | 17 |
| 18 #include "BenchTimer.h" | |
| 19 #include "Stats.h" | |
| 20 | |
| 21 typedef WallTimer Timer; | |
| 22 | |
| 19 __SK_FORCE_IMAGE_DECODER_LINKING; | 23 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 20 | 24 |
| 21 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record ."); | 25 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback."); |
| 22 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); | 26 DEFINE_int32(samples, 10, "Gather this many samples of each picture playback."); |
| 23 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | 27 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); |
| 24 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 28 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
| 25 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); | 29 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); |
| 26 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); | 30 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); |
| 31 DEFINE_int32(verbose, 0, "0: print min sample; " | |
| 32 "1: print min, mean, max and noise indication " | |
| 33 "2: print all samples"); | |
| 27 | 34 |
| 28 static double scale_time(double ms) { | 35 static double timescale() { |
| 29 if (FLAGS_timescale.contains("us")) ms *= 1000; | 36 if (FLAGS_timescale.contains("us")) return 1000; |
| 30 if (FLAGS_timescale.contains("ns")) ms *= 1000000; | 37 if (FLAGS_timescale.contains("ns")) return 1000000; |
| 31 return ms; | 38 return 1; |
| 32 } | 39 } |
| 33 | 40 |
| 34 static SkPicture* rerecord_with_tilegrid(SkPicture& src) { | 41 static SkPicture* rerecord_with_tilegrid(SkPicture& src) { |
| 35 SkTileGridFactory::TileGridInfo info; | 42 SkTileGridFactory::TileGridInfo info; |
| 36 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); | 43 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); |
| 37 info.fMargin.setEmpty(); | 44 info.fMargin.setEmpty(); |
| 38 info.fOffset.setZero(); | 45 info.fOffset.setZero(); |
| 39 SkTileGridFactory factory(info); | 46 SkTileGridFactory factory(info); |
| 40 | 47 |
| 41 SkPictureRecorder recorder; | 48 SkPictureRecorder recorder; |
| 42 src.draw(recorder.beginRecording(src.width(), src.height(), &factory)); | 49 src.draw(recorder.beginRecording(src.width(), src.height(), &factory)); |
| 43 return recorder.endRecording(); | 50 return recorder.endRecording(); |
| 44 } | 51 } |
| 45 | 52 |
| 46 static EXPERIMENTAL::SkPlayback* rerecord_with_skr(SkPicture& src) { | 53 static EXPERIMENTAL::SkPlayback* rerecord_with_skr(SkPicture& src) { |
| 47 EXPERIMENTAL::SkRecording recording(src.width(), src.height()); | 54 EXPERIMENTAL::SkRecording recording(src.width(), src.height()); |
| 48 src.draw(recording.canvas()); | 55 src.draw(recording.canvas()); |
| 49 return recording.releasePlayback(); | 56 return recording.releasePlayback(); |
| 50 } | 57 } |
| 51 | 58 |
| 59 static void draw(const EXPERIMENTAL::SkPlayback& skr, const SkPicture& skp, SkCa nvas* canvas) { | |
| 60 if (FLAGS_skr) { | |
| 61 skr.draw(canvas); | |
| 62 } else { | |
| 63 skp.draw(canvas); | |
| 64 } | |
| 65 } | |
| 66 | |
| 52 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { | 67 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { |
| 53 SkAutoTUnref<SkPicture> picture(rerecord_with_tilegrid(src)); | 68 SkAutoTUnref<SkPicture> picture(rerecord_with_tilegrid(src)); |
| 54 SkAutoTDelete<EXPERIMENTAL::SkPlayback> record(rerecord_with_skr(src)); | 69 SkAutoTDelete<EXPERIMENTAL::SkPlayback> record(rerecord_with_skr(src)); |
| 55 | 70 |
| 56 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), | 71 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), |
| 57 src.height(), | 72 src.height(), |
| 58 scratch, | 73 scratch, |
| 59 src.width() * si zeof(SkPMColor))); | 74 src.width() * si zeof(SkPMColor))); |
| 60 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA GS_tile))); | 75 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA GS_tile))); |
| 61 | 76 |
| 62 BenchTimer timer; | 77 // Draw once to warm any caches. The first sample otherwise can be very noi sy. |
| 63 timer.start(); | 78 draw(*record, *picture, canvas.get()); |
|
jcgregorio
2014/06/16 20:12:48
I know there was talk of throwing away the first d
mtklein
2014/06/16 20:21:28
I would strongly recommend it if any of the data w
| |
| 64 for (int i = 0; i < FLAGS_loops; i++) { | 79 |
| 65 if (FLAGS_skr) { | 80 Timer timer; |
| 66 record->draw(canvas.get()); | 81 SkAutoTMalloc<double> samples(FLAGS_samples); |
| 67 } else { | 82 for (int i = 0; i < FLAGS_samples; i++) { |
| 68 picture->draw(canvas.get()); | 83 // We assume timer overhead (typically, ~30ns) is insignificant |
| 84 // compared to draw runtime (at least ~100us, usually several ms). | |
| 85 timer.start(timescale()); | |
| 86 draw(*record, *picture, canvas.get()); | |
| 87 timer.end(); | |
| 88 samples[i] = timer.fWall; | |
| 89 } | |
| 90 | |
| 91 Stats stats(samples.get(), FLAGS_samples); | |
| 92 if (FLAGS_verbose == 0) { | |
| 93 printf("%g\t%s\n", stats.min, name); | |
| 94 } else if (FLAGS_verbose == 1) { | |
| 95 // Get a rough idea of how noisy the measurements were. | |
| 96 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; | |
| 97 printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, no isePercent, name); | |
| 98 } else if (FLAGS_verbose == 2) { | |
| 99 printf("%s", name); | |
| 100 for (int i = 0; i < FLAGS_samples; i++) { | |
| 101 printf("\t%g", samples[i]); | |
| 69 } | 102 } |
| 103 printf("\n"); | |
| 70 } | 104 } |
| 71 timer.end(); | |
| 72 | |
| 73 const double msPerLoop = timer.fCpu / (double)FLAGS_loops; | |
| 74 printf("%f\t%s\n", scale_time(msPerLoop), name); | |
| 75 } | 105 } |
| 76 | 106 |
| 77 int tool_main(int argc, char** argv); | 107 int tool_main(int argc, char** argv); |
| 78 int tool_main(int argc, char** argv) { | 108 int tool_main(int argc, char** argv) { |
| 79 SkCommandLineFlags::Parse(argc, argv); | 109 SkCommandLineFlags::Parse(argc, argv); |
| 80 SkAutoGraphics autoGraphics; | 110 SkAutoGraphics autoGraphics; |
| 81 | 111 |
| 82 // We share a single scratch bitmap among benches to reduce the profile nois e from allocation. | 112 // We share a single scratch bitmap among benches to reduce the profile nois e from allocation. |
| 83 static const int kMaxArea = 209825221; // tabl_mozilla is this big. | 113 static const int kMaxArea = 209825221; // tabl_mozilla is this big. |
| 84 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); | 114 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 bench(scratch.get(), *src, filename.c_str()); | 146 bench(scratch.get(), *src, filename.c_str()); |
| 117 } | 147 } |
| 118 return failed ? 1 : 0; | 148 return failed ? 1 : 0; |
| 119 } | 149 } |
| 120 | 150 |
| 121 #if !defined SK_BUILD_FOR_IOS | 151 #if !defined SK_BUILD_FOR_IOS |
| 122 int main(int argc, char * const argv[]) { | 152 int main(int argc, char * const argv[]) { |
| 123 return tool_main(argc, (char**) argv); | 153 return tool_main(argc, (char**) argv); |
| 124 } | 154 } |
| 125 #endif | 155 #endif |
| OLD | NEW |