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

Side by Side Diff: tools/VisualBench.cpp

Issue 1159213002: Expand VisualBench to a real benching tool (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks Created 5 years, 6 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
« include/views/SkOSWindow_Unix.h ('K') | « tools/VisualBench.h ('k') | no next file » | 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 2015 Google Inc. 2 * Copyright 2015 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 8
9 #include "VisualBench.h" 9 #include "VisualBench.h"
10 10
11 #include "ProcStats.h"
11 #include "SkApplication.h" 12 #include "SkApplication.h"
12 #include "SkCanvas.h" 13 #include "SkCanvas.h"
13 #include "SkCommandLineFlags.h" 14 #include "SkCommandLineFlags.h"
14 #include "SkCommonFlags.h" 15 #include "SkCommonFlags.h"
15 #include "SkForceLinking.h" 16 #include "SkForceLinking.h"
16 #include "SkGraphics.h" 17 #include "SkGraphics.h"
17 #include "SkGr.h" 18 #include "SkGr.h"
18 #include "SkImageDecoder.h" 19 #include "SkImageDecoder.h"
19 #include "SkOSFile.h" 20 #include "SkOSFile.h"
20 #include "SkStream.h" 21 #include "SkStream.h"
22 #include "Stats.h"
21 #include "Timer.h" 23 #include "Timer.h"
22 #include "gl/GrGLInterface.h" 24 #include "gl/GrGLInterface.h"
23 25
24 __SK_FORCE_IMAGE_DECODER_LINKING; 26 __SK_FORCE_IMAGE_DECODER_LINKING;
25 27
28 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
29 DEFINE_int32(maxFrames, 20, "Number of times to render each skp.");
robertphillips 2015/06/01 14:26:00 Should maxFrames be repeat or samples ?
joshualitt 2015/06/01 16:16:09 Acknowledged.
30 DEFINE_int32(msaa, 0, "Number of msaa samples.");
31
32 static SkString humanize(double ms) {
robertphillips 2015/06/01 14:26:00 add brackets & newlines ?
joshualitt 2015/06/01 16:16:09 Acknowledged.
33 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
34 return HumanizeMs(ms);
35 }
36
37 #define HUMANIZE(time) humanize(time).c_str()
38
26 VisualBench::VisualBench(void* hwnd, int argc, char** argv) 39 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
27 : INHERITED(hwnd) 40 : INHERITED(hwnd)
28 , fCurrentLoops(1)
29 , fCurrentPicture(0) 41 , fCurrentPicture(0)
30 , fCurrentFrame(0) { 42 , fCurrentFrame(0) {
31 SkCommandLineFlags::Parse(argc, argv); 43 SkCommandLineFlags::Parse(argc, argv);
32 44
45 // load all SKPs
33 SkTArray<SkString> skps; 46 SkTArray<SkString> skps;
34 for (int i = 0; i < FLAGS_skps.count(); i++) { 47 for (int i = 0; i < FLAGS_skps.count(); i++) {
35 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 48 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
36 skps.push_back() = FLAGS_skps[i]; 49 skps.push_back() = FLAGS_skps[i];
50 fTimings.push_back().fName = FLAGS_skps[i];
37 } else { 51 } else {
38 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 52 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
39 SkString path; 53 SkString path;
40 while (it.next(&path)) { 54 while (it.next(&path)) {
41 skps.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); 55 skps.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
56 fTimings.push_back().fName = path.c_str();
42 } 57 }
43 } 58 }
44 } 59 }
45 60
46 this->setTitle();
47 this->setupBackend();
48
49 // Load picture for playback
50 for (int i = 0; i < skps.count(); i++) { 61 for (int i = 0; i < skps.count(); i++) {
51 SkFILEStream stream(skps[i].c_str()); 62 SkFILEStream stream(skps[i].c_str());
52 if (stream.isValid()) { 63 if (stream.isValid()) {
53 fPictures.push_back(SkPicture::CreateFromStream(&stream)); 64 fPictures.push_back(SkPicture::CreateFromStream(&stream));
54 } else { 65 } else {
55 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str()); 66 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str());
56 } 67 }
57 } 68 }
69
70 if (fPictures.empty()) {
71 SkDebugf("no valid skps found\n");
72 }
73
74 this->setTitle();
75 this->setupBackend();
58 } 76 }
59 77
60 VisualBench::~VisualBench() { 78 VisualBench::~VisualBench() {
61 for (int i = 0; i < fPictures.count(); i++) { 79 for (int i = 0; i < fPictures.count(); i++) {
62 fPictures[i]->~SkPicture(); 80 fPictures[i]->~SkPicture();
63 } 81 }
64 INHERITED::detach(); 82 INHERITED::detach();
65 } 83 }
66 84
67 void VisualBench::setTitle() { 85 void VisualBench::setTitle() {
68 SkString title("VisualBench"); 86 SkString title("VisualBench");
69 INHERITED::setTitle(title.c_str()); 87 INHERITED::setTitle(title.c_str());
70 } 88 }
71 89
72 SkSurface* VisualBench::createSurface() { 90 SkSurface* VisualBench::createSurface() {
73 SkSurfaceProps props(INHERITED::getSurfaceProps()); 91 SkSurfaceProps props(INHERITED::getSurfaceProps());
74 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props); 92 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
75 } 93 }
76 94
77 bool VisualBench::setupBackend() { 95 bool VisualBench::setupBackend() {
78 this->setColorType(kRGBA_8888_SkColorType); 96 this->setColorType(kRGBA_8888_SkColorType);
79 this->setVisibleP(true); 97 this->setVisibleP(true);
80 this->setClipToBounds(false); 98 this->setClipToBounds(false);
81 99
82 if (!this->attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo)) { 100 if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
83 SkDebugf("Not possible to create backend.\n"); 101 SkDebugf("Not possible to create backend.\n");
84 INHERITED::detach(); 102 INHERITED::detach();
85 return false; 103 return false;
86 } 104 }
87 105
88 this->setFullscreen(true); 106 this->setFullscreen(true);
89 this->setVsync(false); 107 this->setVsync(false);
108 this->resetContext();
109 return true;
110 }
90 111
112 void VisualBench::resetContext() {
91 fInterface.reset(GrGLCreateNativeInterface()); 113 fInterface.reset(GrGLCreateNativeInterface());
92 SkASSERT(fInterface); 114 SkASSERT(fInterface);
93 115
94 // setup contexts 116 // setup contexts
95 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get())); 117 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get()));
96 SkASSERT(fContext); 118 SkASSERT(fContext);
97 119
98 // setup rendertargets 120 // setup rendertargets
99 this->setupRenderTarget(); 121 this->setupRenderTarget();
100 return true;
101 } 122 }
102 123
103 void VisualBench::setupRenderTarget() { 124 void VisualBench::setupRenderTarget() {
104 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext )); 125 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext ));
105 } 126 }
106 127
107 void VisualBench::draw(SkCanvas* canvas) { 128 void VisualBench::timeFrame(SkCanvas* canvas) {
108 fCurrentFrame++;
109 WallTimer timer; 129 WallTimer timer;
bsalomon 2015/06/01 13:49:54 I think you should time outside the loop
joshualitt 2015/06/01 16:16:09 Acknowledged.
110 timer.start(); 130 timer.start();
111 for (int i = 0; i < fCurrentLoops; i++) { 131 canvas->drawPicture(fPictures[fCurrentPicture]);
112 canvas->drawPicture(fPictures[fCurrentPicture]);
113 }
114 // in case we have queued drawing calls 132 // in case we have queued drawing calls
115 fContext->flush(); 133 fContext->flush();
116 INHERITED::present(); 134 INHERITED::present();
117 timer.end(); 135 timer.end();
136 if (fCurrentFrame > FLAGS_gpuFrameLag) {
137 fTimings[fCurrentPicture].fMeasurements.push_back(timer.fWall);
138 }
139 }
118 140
119 SkDebugf("%s\n", HumanizeMs(timer.fWall).c_str()); 141 void VisualBench::printStats() {
142 const SkTArray<double>& measurements = fTimings[fCurrentPicture].fMeasuremen ts;
143 if (FLAGS_verbose) {
144 for (int i = 0; i < measurements.count(); i++) {
145 SkDebugf("%s ", HUMANIZE(measurements[i]));
146 }
147 SkDebugf("%s\n", fTimings[fCurrentPicture].fName.c_str());
148 } else {
149 SkASSERT(measurements.count());
150 Stats stats(measurements.begin(), measurements.count());
robertphillips 2015/06/01 14:31:07 stdDevPercent ?
joshualitt 2015/06/01 16:16:09 Acknowledged.
151 const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
152 SkDebugf("%4d/%-4dMB\t%s\t%s\t%s\t%s\t%.0f%%\t%s\n"
robertphillips 2015/06/01 14:26:00 I think we only do the "lead-with-," thing for cto
joshualitt 2015/06/01 16:16:09 Acknowledged.
153 , sk_tools::getCurrResidentSetSizeMB()
154 , sk_tools::getMaxResidentSetSizeMB()
robertphillips 2015/06/01 14:31:07 This probably isn't yours but why isn't this fMin
joshualitt 2015/06/01 16:16:09 no idea, might be Mike Klein's code.
155 , HUMANIZE(stats.min)
156 , HUMANIZE(stats.median)
157 , HUMANIZE(stats.mean)
158 , HUMANIZE(stats.max)
159 , stddev_percent
160 , fTimings[fCurrentPicture].fName.c_str()
161 );
162 }
163 }
164
165 void VisualBench::draw(SkCanvas* canvas) {
166 if (fCurrentPicture < fPictures.count()) {
167 if (fCurrentFrame++ < FLAGS_maxFrames) {
168 this->timeFrame(canvas);
169 } else {
170 this->printStats();
171 fCurrentPicture++;
172 fCurrentFrame = 0;
173 this->resetContext();
174 }
175 } else {
176 this->closeWindow();
177 }
120 178
121 // Invalidate the window to force a redraw. Poor man's animation mechanism. 179 // Invalidate the window to force a redraw. Poor man's animation mechanism.
122 this->inval(NULL); 180 this->inval(NULL);
123 } 181 }
124 182
125 void VisualBench::onSizeChange() { 183 void VisualBench::onSizeChange() {
126 this->setupRenderTarget(); 184 this->setupRenderTarget();
127 } 185 }
128 186
129 bool VisualBench::onHandleChar(SkUnichar unichar) { 187 bool VisualBench::onHandleChar(SkUnichar unichar) {
130 return true; 188 return true;
131 } 189 }
132 190
133 // Externally declared entry points 191 // Externally declared entry points
134 void application_init() { 192 void application_init() {
135 SkGraphics::Init(); 193 SkGraphics::Init();
136 SkEvent::Init(); 194 SkEvent::Init();
137 } 195 }
138 196
139 void application_term() { 197 void application_term() {
140 SkEvent::Term(); 198 SkEvent::Term();
141 SkGraphics::Term(); 199 SkGraphics::Term();
142 } 200 }
143 201
144 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { 202 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
145 return new VisualBench(hwnd, argc, argv); 203 return new VisualBench(hwnd, argc, argv);
146 } 204 }
147 205
OLDNEW
« include/views/SkOSWindow_Unix.h ('K') | « tools/VisualBench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698