Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: tools/bench_playback.cpp

Issue 257563006: use BenchTimer, print in µs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: stray u Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gyp/tools.gyp ('k') | tools/bench_record.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
8 #include "SkCommandLineFlags.h" 9 #include "SkCommandLineFlags.h"
9 #include "SkForceLinking.h" 10 #include "SkForceLinking.h"
10 #include "SkGraphics.h" 11 #include "SkGraphics.h"
11 #include "SkOSFile.h" 12 #include "SkOSFile.h"
12 #include "SkPicture.h" 13 #include "SkPicture.h"
13 #include "SkRecordDraw.h" 14 #include "SkRecordDraw.h"
14 #include "SkRecordOpts.h" 15 #include "SkRecordOpts.h"
15 #include "SkRecorder.h" 16 #include "SkRecorder.h"
16 #include "SkStream.h" 17 #include "SkStream.h"
17 #include "SkString.h" 18 #include "SkString.h"
18 #include "SkTime.h"
19 19
20 __SK_FORCE_IMAGE_DECODER_LINKING; 20 __SK_FORCE_IMAGE_DECODER_LINKING;
21 21
22 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record ."); 22 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record .");
23 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); 23 DEFINE_int32(loops, 10, "Number of times to play back each SKP.");
24 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); 24 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture.");
25 DEFINE_int32(tile, 1000000000, "Simulated tile size."); 25 DEFINE_int32(tile, 1000000000, "Simulated tile size.");
26 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); 26 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench.");
27 27
28 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { 28 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) {
29 // We don't use the public SkRecording interface here because we need kWrite Only_Mode. 29 // We don't use the public SkRecording interface here because we need kWrite Only_Mode.
30 // (We don't want SkPicturePlayback to be able to optimize playing into our SkRecord.) 30 // (We don't want SkPicturePlayback to be able to optimize playing into our SkRecord.)
31 SkRecord record; 31 SkRecord record;
32 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.h eight()); 32 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.h eight());
33 src.draw(&recorder); 33 src.draw(&recorder);
34 34
35 SkRecordOptimize(&record); 35 SkRecordOptimize(&record);
36 36
37 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), 37 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(),
38 src.height(), 38 src.height(),
39 scratch, 39 scratch,
40 src.width() * si zeof(SkPMColor))); 40 src.width() * si zeof(SkPMColor)));
41 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA GS_tile))); 41 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA GS_tile)));
42 42
43 const SkMSec start = SkTime::GetMSecs(); 43 BenchTimer timer;
44 timer.start();
44 for (int i = 0; i < FLAGS_loops; i++) { 45 for (int i = 0; i < FLAGS_loops; i++) {
45 if (FLAGS_skr) { 46 if (FLAGS_skr) {
46 SkRecordDraw(record, canvas.get()); 47 SkRecordDraw(record, canvas.get());
47 } else { 48 } else {
48 src.draw(canvas.get()); 49 src.draw(canvas.get());
49 } 50 }
50 } 51 }
52 timer.end();
51 53
52 const SkMSec elapsed = SkTime::GetMSecs() - start; 54 const double msPerLoop = timer.fCpu / (double)FLAGS_loops;
53 const double msPerLoop = elapsed / (double)FLAGS_loops; 55 printf("%u\t%s\n", unsigned(1000 * msPerLoop), name);
54 printf("%6.2f\t%s\n", msPerLoop, name);
55 } 56 }
56 57
57 int tool_main(int argc, char** argv); 58 int tool_main(int argc, char** argv);
58 int tool_main(int argc, char** argv) { 59 int tool_main(int argc, char** argv) {
59 SkCommandLineFlags::Parse(argc, argv); 60 SkCommandLineFlags::Parse(argc, argv);
60 SkAutoGraphics autoGraphics; 61 SkAutoGraphics autoGraphics;
61 62
62 // We share a single scratch bitmap among benches to reduce the profile nois e from allocation. 63 // We share a single scratch bitmap among benches to reduce the profile nois e from allocation.
63 static const int kMaxArea = 209825221; // tabl_mozilla is this big. 64 static const int kMaxArea = 209825221; // tabl_mozilla is this big.
64 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); 65 SkAutoTMalloc<SkPMColor> scratch(kMaxArea);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bench(scratch.get(), *src, filename.c_str()); 97 bench(scratch.get(), *src, filename.c_str());
97 } 98 }
98 return failed ? 1 : 0; 99 return failed ? 1 : 0;
99 } 100 }
100 101
101 #if !defined SK_BUILD_FOR_IOS 102 #if !defined SK_BUILD_FOR_IOS
102 int main(int argc, char * const argv[]) { 103 int main(int argc, char * const argv[]) {
103 return tool_main(argc, (char**) argv); 104 return tool_main(argc, (char**) argv);
104 } 105 }
105 #endif 106 #endif
OLDNEW
« no previous file with comments | « gyp/tools.gyp ('k') | tools/bench_record.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698