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

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
« no previous file with comments | « 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"
21 #include "Timer.h" 22 #include "Stats.h"
22 #include "gl/GrGLInterface.h" 23 #include "gl/GrGLInterface.h"
23 24
24 __SK_FORCE_IMAGE_DECODER_LINKING; 25 __SK_FORCE_IMAGE_DECODER_LINKING;
25 26
27 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
28 DEFINE_int32(samples, 10, "Number of times to render each skp.");
29 DEFINE_int32(loops, 5, "Number of times to time.");
30 DEFINE_int32(msaa, 0, "Number of msaa samples.");
31
32 static SkString humanize(double ms) {
33 if (FLAGS_verbose) {
34 return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
35 }
36 return HumanizeMs(ms);
37 }
38
39 #define HUMANIZE(time) humanize(time).c_str()
40
26 VisualBench::VisualBench(void* hwnd, int argc, char** argv) 41 VisualBench::VisualBench(void* hwnd, int argc, char** argv)
27 : INHERITED(hwnd) 42 : INHERITED(hwnd)
28 , fCurrentLoops(1) 43 , fLoop(0)
29 , fCurrentPicture(0) 44 , fCurrentPicture(0)
30 , fCurrentFrame(0) { 45 , fCurrentSample(0)
46 , fState(kPreWarm_State) {
31 SkCommandLineFlags::Parse(argc, argv); 47 SkCommandLineFlags::Parse(argc, argv);
32 48
49 // load all SKPs
33 SkTArray<SkString> skps; 50 SkTArray<SkString> skps;
34 for (int i = 0; i < FLAGS_skps.count(); i++) { 51 for (int i = 0; i < FLAGS_skps.count(); i++) {
35 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 52 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
36 skps.push_back() = FLAGS_skps[i]; 53 skps.push_back() = FLAGS_skps[i];
54 fTimings.push_back().fName = FLAGS_skps[i];
37 } else { 55 } else {
38 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 56 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
39 SkString path; 57 SkString path;
40 while (it.next(&path)) { 58 while (it.next(&path)) {
41 skps.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); 59 skps.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
60 fTimings.push_back().fName = path.c_str();
42 } 61 }
43 } 62 }
44 } 63 }
45 64
46 this->setTitle();
47 this->setupBackend();
48
49 // Load picture for playback
50 for (int i = 0; i < skps.count(); i++) { 65 for (int i = 0; i < skps.count(); i++) {
51 SkFILEStream stream(skps[i].c_str()); 66 SkFILEStream stream(skps[i].c_str());
52 if (stream.isValid()) { 67 if (stream.isValid()) {
53 fPictures.push_back(SkPicture::CreateFromStream(&stream)); 68 fPictures.push_back(SkPicture::CreateFromStream(&stream));
54 } else { 69 } else {
55 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str()); 70 SkDebugf("couldn't load picture at \"path\"\n", skps[i].c_str());
56 } 71 }
57 } 72 }
73
74 if (fPictures.empty()) {
75 SkDebugf("no valid skps found\n");
76 }
77
78 this->setTitle();
79 this->setupBackend();
58 } 80 }
59 81
60 VisualBench::~VisualBench() { 82 VisualBench::~VisualBench() {
61 for (int i = 0; i < fPictures.count(); i++) { 83 for (int i = 0; i < fPictures.count(); i++) {
62 fPictures[i]->~SkPicture(); 84 fPictures[i]->~SkPicture();
63 } 85 }
64 INHERITED::detach(); 86 INHERITED::detach();
65 } 87 }
66 88
67 void VisualBench::setTitle() { 89 void VisualBench::setTitle() {
68 SkString title("VisualBench"); 90 SkString title("VisualBench");
69 INHERITED::setTitle(title.c_str()); 91 INHERITED::setTitle(title.c_str());
70 } 92 }
71 93
72 SkSurface* VisualBench::createSurface() { 94 SkSurface* VisualBench::createSurface() {
73 SkSurfaceProps props(INHERITED::getSurfaceProps()); 95 SkSurfaceProps props(INHERITED::getSurfaceProps());
74 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props); 96 return SkSurface::NewRenderTargetDirect(fRenderTarget, &props);
75 } 97 }
76 98
77 bool VisualBench::setupBackend() { 99 bool VisualBench::setupBackend() {
78 this->setColorType(kRGBA_8888_SkColorType); 100 this->setColorType(kRGBA_8888_SkColorType);
79 this->setVisibleP(true); 101 this->setVisibleP(true);
80 this->setClipToBounds(false); 102 this->setClipToBounds(false);
81 103
82 if (!this->attach(kNativeGL_BackEndType, 0 /*msaa*/, &fAttachmentInfo)) { 104 if (!this->attach(kNativeGL_BackEndType, FLAGS_msaa, &fAttachmentInfo)) {
83 SkDebugf("Not possible to create backend.\n"); 105 SkDebugf("Not possible to create backend.\n");
84 INHERITED::detach(); 106 INHERITED::detach();
85 return false; 107 return false;
86 } 108 }
87 109
88 this->setFullscreen(true); 110 this->setFullscreen(true);
89 this->setVsync(false); 111 this->setVsync(false);
112 this->resetContext();
113 return true;
114 }
90 115
116 void VisualBench::resetContext() {
91 fInterface.reset(GrGLCreateNativeInterface()); 117 fInterface.reset(GrGLCreateNativeInterface());
92 SkASSERT(fInterface); 118 SkASSERT(fInterface);
93 119
94 // setup contexts 120 // setup contexts
95 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get())); 121 fContext.reset(GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)fInter face.get()));
96 SkASSERT(fContext); 122 SkASSERT(fContext);
97 123
98 // setup rendertargets 124 // setup rendertargets
99 this->setupRenderTarget(); 125 this->setupRenderTarget();
100 return true;
101 } 126 }
102 127
103 void VisualBench::setupRenderTarget() { 128 void VisualBench::setupRenderTarget() {
104 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext )); 129 fRenderTarget.reset(this->renderTarget(fAttachmentInfo, fInterface, fContext ));
105 } 130 }
106 131
107 void VisualBench::draw(SkCanvas* canvas) { 132 inline void VisualBench::renderFrame(SkCanvas* canvas) {
108 fCurrentFrame++; 133 canvas->drawPicture(fPictures[fCurrentPicture]);
109 WallTimer timer;
110 timer.start();
111 for (int i = 0; i < fCurrentLoops; i++) {
112 canvas->drawPicture(fPictures[fCurrentPicture]);
113 }
114 // in case we have queued drawing calls
115 fContext->flush(); 134 fContext->flush();
116 INHERITED::present(); 135 INHERITED::present();
117 timer.end(); 136 }
118 137
119 SkDebugf("%s\n", HumanizeMs(timer.fWall).c_str()); 138 void VisualBench::printStats() {
139 const SkTArray<double>& measurements = fTimings[fCurrentPicture].fMeasuremen ts;
140 if (FLAGS_verbose) {
141 for (int i = 0; i < measurements.count(); i++) {
142 SkDebugf("%s ", HUMANIZE(measurements[i]));
143 }
144 SkDebugf("%s\n", fTimings[fCurrentPicture].fName.c_str());
145 } else {
146 SkASSERT(measurements.count());
147 Stats stats(measurements.begin(), measurements.count());
148 const double stdDevPercent = 100 * sqrt(stats.var) / stats.mean;
149 SkDebugf("%4d/%-4dMB\t%s\t%s\t%s\t%s\t%.0f%%\t%s\n",
150 sk_tools::getCurrResidentSetSizeMB(),
151 sk_tools::getMaxResidentSetSizeMB(),
152 HUMANIZE(stats.min),
153 HUMANIZE(stats.median),
154 HUMANIZE(stats.mean),
155 HUMANIZE(stats.max),
156 stdDevPercent,
157 fTimings[fCurrentPicture].fName.c_str());
158 }
159 }
160
161 void VisualBench::timePicture(SkCanvas* canvas) {
162 this->renderFrame(canvas);
163 switch (fState) {
164 case kPreWarm_State: {
165 if (fCurrentSample >= FLAGS_gpuFrameLag) {
166 // TODO we currently time across all frames to make sure we capt ure all GPU work
167 // We should also rendering an empty SKP to get a baseline to su btract from
168 // our timing
169 fState = kTiming_State;
170 fCurrentSample -= FLAGS_gpuFrameLag;
171 fTimer.start();
172 } else {
173 fCurrentSample++;
174 }
175 break;
176 }
177 case kTiming_State: {
178 if (fCurrentSample >= FLAGS_samples) {
179 fTimer.end();
180 fTimings[fCurrentPicture].fMeasurements.push_back(fTimer.fWall / FLAGS_samples);
181 this->resetContext();
182 fTimer = WallTimer();
183 fState = kPreWarm_State;
184 fCurrentSample = 0;
185 if (fLoop++ > FLAGS_loops) {
186 this->printStats();
187 fCurrentPicture++;
188 fLoop = 0;
189 }
190 } else {
191 fCurrentSample++;
192 }
193 break;
194 }
195 }
196 }
197
198 void VisualBench::draw(SkCanvas* canvas) {
199 if (fCurrentPicture < fPictures.count()) {
200 this->timePicture(canvas);
201 } else {
202 this->closeWindow();
203 }
120 204
121 // Invalidate the window to force a redraw. Poor man's animation mechanism. 205 // Invalidate the window to force a redraw. Poor man's animation mechanism.
122 this->inval(NULL); 206 this->inval(NULL);
123 } 207 }
124 208
125 void VisualBench::onSizeChange() { 209 void VisualBench::onSizeChange() {
126 this->setupRenderTarget(); 210 this->setupRenderTarget();
127 } 211 }
128 212
129 bool VisualBench::onHandleChar(SkUnichar unichar) { 213 bool VisualBench::onHandleChar(SkUnichar unichar) {
130 return true; 214 return true;
131 } 215 }
132 216
133 // Externally declared entry points 217 // Externally declared entry points
134 void application_init() { 218 void application_init() {
135 SkGraphics::Init(); 219 SkGraphics::Init();
136 SkEvent::Init(); 220 SkEvent::Init();
137 } 221 }
138 222
139 void application_term() { 223 void application_term() {
140 SkEvent::Term(); 224 SkEvent::Term();
141 SkGraphics::Term(); 225 SkGraphics::Term();
142 } 226 }
143 227
144 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) { 228 SkOSWindow* create_sk_window(void* hwnd, int argc, char** argv) {
145 return new VisualBench(hwnd, argc, argv); 229 return new VisualBench(hwnd, argc, argv);
146 } 230 }
147 231
OLDNEW
« no previous file with comments | « tools/VisualBench.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698